第一次發佈所以請善待。需要在宏中間手動打開excel文件
從模板文件,我運行一個宏創建一個新的文件夾,在它的模板文件的副本。然後我重新命名並更新它。有一次,我需要手動從網站上下載文件並打開它,然後啓動另一個宏來完成更新。
我最初試圖做到這一點從一個獨特的宏觀,但我得到的問題,宏將繼續運行Excel文件來得及打開之前。
我現在已經在2分割我的宏在第一次宏觀結束,我稱之爲有指令的用戶窗體,並繼續按鈕。這個想法是,我會在用戶窗體打開時下載文件,並在打開文件時點擊「繼續」。
由於某種原因,文件根本無法打開。看起來好像用戶窗體或宏停止打開文件。不過,如果我使用調試功能運行它,它工作正常...
Public strSN As String, strPart As String, strPath As String
Sub create_new()
' Create Folder if it doesn't exist
'Dim strSN As String, strPart As String, strPath As String
'strSN = SerialNumber.Value
'strPart = PartNumber.Value
'strPath = "M:\Quality\QUALITY ASSURANCE\DOC\Rental Folder\Scanned MRB's\"
' close userform
welcomeform.Hide
'set Microsoft scription runtime reference to allow creation of folder macro
On Error Resume Next
ThisWorkbook.VBProject.References.AddFromGUID "{420B2830-E718-11CF-893D- 00A0C9054228}", 1, 0
On Error GoTo 0
If Not FolderExists(strSN) Then
'Serial Number folder doesn't exist, so create full path
FolderCreate strPath & strSN
End If
' Create new file in new folder
On Error Resume Next
ActiveWorkbook.SaveCopyAs Filename:=strPath & strSN & "\" & strPart & " " & strSN & " " & "SNR.xlsm"
If Err.Number <> 0 Then
MsgBox "Copy error: " & strPath & "TEMPLATE SNR.xlsm"
End If
On Error GoTo 0
' open new file without showing it or opening macros
Application.EnableEvents = False 'disable Events
Workbooks.Open Filename:=strPath & strSN & "\" & strPart & " " & strSN & " " & "SNR.xlsm"
Application.EnableEvents = True 'enable Events
' Modify serial number and part number in traceability summary form
Sheets("Traceability Summary Form").Activate
Sheets("Traceability Summary Form").Unprotect
Range("A7").Value = strSN
Range("C7").Value = strPart
' update file with ITP
Call Download_itp
End Sub
Sub Download_itp()
downloaditp.Show
End Sub
在download_itp窗體:
Sub update_traceable_items()
'
' Macro to update the SNR tab with the traceable items from the ITP
'
downloaditp.Hide
' copy ITP in file
Application.ActiveProtectedViewWindow.Edit
ActiveSheet.Name = "ITP"
ActiveSheet.Copy after:=Workbooks(strPart & " " & strSN & " " & "SNR.xlsm").Sheets("SNR template")
:
Sub continue_Click()
Call update_traceable_items
End Sub
然後第二個宏與代碼開始
任何幫助,將不勝感激! 感謝
試試'application.wait'而不是userform? – findwindow
你*有*手動下載文件?這是可能的(對於大多數文件我相信)有VBA下載文件X到文件夾Y. – BruceWayne
@findwindow,我試過'application.wait'之前,它沒有工作。 – charlotteF