[英]How to automatically cancel file open prompts using vba
我在excel中為關閉的工作簿的外部鏈接創建了動態文本字符串,需要將其轉換為公式。 有些文件尚不存在,但是我需要以公式形式創建的鏈接。 當我執行以下代碼時,系統提示我打開不存在的文件。 有沒有一種方法可以自動取消提示,以便無論如何都可以輸入公式? 手動取消gazillion提示很煩人!
Sub GetData()
Dim path As String, r As Single, c As Single
Application.Calculation = xlCalculationManual
For c = 0 To 29
For r = 0 To 1000
path = Worksheets("String formulas").Range("a3").Offset(r, c)
Worksheets("Transformed data").Range("bl3").Offset(r, c).Formula = "=" & path
Next r
Next c
End Sub
嘗試使用此更新的代碼
Sub GetData()
Dim path As String, r As Single, c As Single
Set fso = CreateObject("scripting.filesystemobject")
Application.Calculation = xlCalculationManual
For c = 0 To 29
For r = 0 To 1000
path = Worksheets("String formulas").Range("a3").Offset(r, c)
If fso.FileExists(path) = True Then
Worksheets("Transformed data").Range("bl3").Offset(r, c).Formula = "=" & path
End If
Next r
Next c
End Sub
您可以通過切換Application.DisplayAlerts
來解決此問題。
Sub GetData()
Dim path As String, r As Single, c As Single
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
For c = 0 To 29
For r = 0 To 1000
path = Worksheets("String formulas").Range("a3").Offset(r, c)
Worksheets("Transformed data").Range("bl3").Offset(r, c).Formula = "=" & path
Next r
Next c
Application.DisplayAlerts = True
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.