How do I declare a global variable in VBA?

前端 未结 8 1173

I wrote the following code:

Function find_results_idle()

    Public iRaw As Integer
    Public iColumn As Integer
    iRaw = 1
    iColumn = 1
8条回答
  •  迷失自我
    2020-11-22 09:07

    Create a public integer in the General Declaration.

    Then in your function you can increase its value each time. See example (function to save attachements of an email as CSV).

    Public Numerator As Integer
    
    Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    Dim FileName As String
    
    saveFolder = "c:\temp\"
    
         For Each objAtt In itm.Attachments
                FileName = objAtt.DisplayName & "_" & Numerator & "_" & Format(Now, "yyyy-mm-dd H-mm-ss") & ".CSV"
                          objAtt.SaveAsFile saveFolder & "\" & FileName
                          Numerator = Numerator + 1
    
              Set objAtt = Nothing
         Next
    End Sub
    

提交回复
热议问题