簡體   English   中英

使用 Excel VBA 消息框

[英]Using an Excel VBA msgbox

我運行了這段代碼,它可以工作,但是每次 d 都會彈出 MSGBOX。 如果回答是,我希望它只運行一次,而不是每次都詢問。 我怎樣才能完成這項工作?

For d = 2 To 10
    destination_folder = Trim(aw.Worksheets(1).Range("A" & d).Value)
    Dim strFileName As String
    Dim strFileExists As String
    
        strFileName = destination_folder & monthandyear
        strFileExists = Dir(strFileName)
    
       If strFileExists = "" Then
            If MsgBox("The file doesn't exist would you like to create one for " & monthandyear & "?", vbYesNo) = vbNo Then Exit Sub
        Else
            If MsgBox("The selected file exists", vbOKOnly) = vb Then Exit Sub
        End If
    
    Set FSO = CreateObject("Scripting.filesystemobject")
    FSO.Copyfile (source_folder & source_file), destination_folder & monthandyear, True
    
    Next
    
    End Sub

將消息框的值存儲在變量中並檢查該值。 6 = 是,7 = 否

For d = 2 To 10
    destination_folder = Trim(aw.Worksheets(1).Range("A" & d).Value)
    Dim strFileName As String
    Dim strFileExists As String
    Dim yesno As Long
    
        strFileName = destination_folder & monthandyear
        strFileExists = Dir(strFileName)
        
        If strFileExists = "" Then
            If Not yesno = 6 Then
                yesno = MsgBox("The file doesn't exist would you like to create one for " & monthandyear & "?", vbYesNo)
                If yesno = 7 Then Exit Sub
            End If
        Else
            If MsgBox("The selected file exists", vbOKOnly) = vb Then Exit Sub
        End If
    
    Set FSO = CreateObject("Scripting.filesystemobject")
    FSO.Copyfile (source_folder & source_file), destination_folder & monthandyear, True
    
    Next

暫無
暫無

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

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