代码1  workbook.open()  会直接先打开其他表,在前台蹦出来比较傻

  • Workbooks.Open(path) 这里得是 绝对路径
Sub williamding21()
'测试跨表操作的问题,在A表中操作B表

Dim wb1

path1 = "C:\Users\Administrator\Desktop"
path2 = "test1.xlsm"


Workbooks.Open (path1 & "\" & path2)

Debug.Print Workbooks.Open(path1 & "\" & path2).Name
Debug.Print Workbooks(path2).Sheets("sheet1").Cells(5, 5).Value


End Sub

 

代码2 前台不会蹦出来,但实际也打开了

Sub williamding20()
'测试跨表操作的问题,在A表中操作B表

Dim wb1

path1 = "C:\Users\Administrator\Desktop"
path2 = "test1.xlsm"


Set wb1 = CreateObject(path1 & "\" & path2)    '仍然会再后台打开这个表
Debug.Print wb1.Name
Debug.Print wb1.Sheets("sheet1").Cells(5, 5).Value


End Sub

 

代码3  关于屏幕刷新,实现不跳出的效果

  • application.screenupdating=false  这句话不能写在过程外,必须写在过程内
  • application.screenupdating=false  这句话写在过程外,会显示“无效的外部过程”
  • 一般记得在结尾再打开
  • application.screenupdating=true

 

Sub williamDing32()
Application.ScreenUpdating = False
Dim wb1 As Object

Set wb1 = Workbooks.Open("C:\Users\Administrator\Desktop\test1.xlsm")
Debug.Print wb1.Worksheets("sheet1").Cells(5, 5)


Application.ScreenUpdating = True
End Sub

 

代码4 

 

Workbooks.Open Filename
ActiveWindow.Visible = False

 

 

这个可以在这个过程内先禁用 其他新打开 表的 打开事件等

Application.EnableEvents = False
之后再调用,看看行不行

 

workbooks.open()

workbooks.close()

 

 

后台打开

禁止EXCEL显示

https://zhidao.baidu.com/question/508811410.html

https://blog.csdn.net/thgz/article/details/6601610

 

Sub test1()
Application.DisplayAlerts = False
Dim wb As Workbook
Set wb = Workbooks.Open(ThisWorkbook.Path & "\AA.xls")
wb.Sheets(1).[a1] = ThisWorkbook.Sheets(1).[a1]
wb.Save: wb.Close True
Application.DisplayAlerts = True
End Sub
 

用GetObject打开时看不见,但还是要关闭。
Set wb = GetObject(yourpath & "\" & myfile)
wb.close false

 

Sub 后台打开()
Application.ScreenUpdating = False
Workbooks.Open Filename:="D:\test.xls"
ActiveWindow.Visible = False
Application.ScreenUpdating = True
End Sub


Sub 取消隐藏()
Windows("text.xls").Visible = True
End Sub

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐