我有一個簡單的小Excel宏,用於打開模板,請求文件名並保存文件。它從Microsoft VBA窗口運行而沒有問題,但是當從Excel中使用快捷鍵時,它會打開文件,但不顯示輸入框。當從快捷鍵運行宏時不會出現輸入框
Sub NewCommentSheet()
'
' NewCommentSheet Macro
' Opens the Comments and Recheck template. A dialog box asks for the data module name,
' which is then used for the filename of the new comment sheet.
'
' Keyboard Shortcut: Ctrl+Shift+N
'
'Opens the file
Workbooks.Open Filename:= _
"C:\Users\Kelly.Keck\Documents\Projects\SBIR\QA Notes\Comments and Recheck Template.xlsx"
'Defines variables. moduleName comes from the input box. newFileName uses moduleName _
to create a filename: "Comments for [moduleName].xslx"
Dim moduleName As String
Dim newFileName As String
'Asks the user for the data module name--default is set as the common portion of _
the filename.
moduleName = Application.InputBox(Prompt:="Enter the name of the data module.", _
Title:="Data Module Title", Default:="DMTitle-")
'Checks to see if input was canceled. If canceled, ends the macro to avoid saving with an incorrect filename.
If moduleName = "False" Then End
'Saves file with the new name.
newFileName = "Comments for " & moduleName & ".xslx"
ActiveWorkbook.SaveAs Filename:=newFileName
End Sub
添加
DoEvents
是的,它是一個衆所周知的問題(我希望如此)。讓我發佈爲什麼發生這種情況:) –順便說一句,當我說「我希望如此」時,我的意思是我希望很多人都知道這種限制... –