簡體   English   中英

我無法讓workbook.open打開一個用來打開的文件而不需要更改代碼。 為什么會出錯?

[英]I can't get workbook.open to open a file it use to open with no changes to the code. Why is it giving an error?

我正在編寫一個依賴於另一個工作簿中的信息的宏。 昨天我啟動並運行代碼允許用戶輸入案例編號,然后從那里構建工作簿標題(例如“CaseDownload_72503”)並打開帶有該標題的工作簿。 我今天回到我的電腦,我收到錯誤“運行時錯誤'1004'抱歉,我們找不到CaseDownload_72503.xlsx。它是否可能被移動,重命名或刪除?” 自昨天以來我沒有更改工作簿的位置或名稱,我的代碼沒有被更改。 我不知道為什么它找不到工作簿

我已經嘗試將文檔移動到桌面,試圖讓它找到它。 我已經嘗試更改標題,看看我是否可以使用另一個標題來打開它。 當然,我關閉了所有與excel相關的窗口並重新啟動了計算機,沒有任何改變。

'''''''''''''''''''''''''''''''
'               SECTION 1
' This section accepts the case
' number from the user and then
' finds the dcouments that
' correspond to that case number
''''''''''''''''''''''''''''''''

Dim casenum, filename As String

'accepts user input for the case number they wish to open the workbook 'for
casenum = InputBox("Enter the case number for which you would like to generate the email template.")
'concatenates the case number with the beginning of the file naming 'standard
filename = "CaseDownload_" & casenum
'opens the file that matches'
Workbooks.Open filename:=filename

它應該只是使用提供的名稱打開工作簿,然后后面的(未包含的)代碼開始從打開的工作簿中獲取信息並將其放入另一個工作簿中。 它找不到工作簿並說它不存在。

嘗試打開完整的文件規范 ; 就像是:

Sub Marine()
    Dim casenum As String, filename As String

    casenum = Application.InputBox(Prompt:="enter case number", Type:=1)
    filename = "CaseDownload_" & casenum
    Workbooks.Open filename:="c:\users\garys\desktop\" & filename & ".xlsx"

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM