VBA - 多个字符串变量 - 避免多次引用它们

时间:2016-11-02 23:56:34

标签: vba excel-vba excel

我正在尝试创建一个.xlsm网页抓取模板。我希望它保持非常灵活。完全我想声明所有字符串变量,将它们列在数组中,并且能够在需要时仅通过键入变量名称从数组VbNullstring值中分配每个变量。

有可能接近这个吗?也许与脚本目录?

Public ScrapingCancelled As Boolean
Public IE As Object
Public WS As Worksheet
Public RegEx As New RegExp
Public Company As String, Address As String, Phone As String, Email As String, Website As String
Public resultCounter As Long

Public Sub ClearGlobals()

ScrapingCancelled = False

Set IE = Nothing
Set WS = Nothing
Set RegEx = Nothing

ClearOutputVariables

resultCounter = 1

End Sub

Public Sub ClearOutputVariables()

Company = vbNullString
Address = vbNullString
Phone = vbNullString
Email = vbNullString
Website = vbNullString

End Sub


Public Sub PrintResults()

Dim results As Variant 'not string because of phone numbers - they are converted from string to long in variant array

results = Array(Company, Address, Phone, Email, Website)

With WS
    Range(.Cells(resultCounter, 1), .Cells(resultCounter, UBound(results) + 1)).Value2 = results
End With

ClearOutputVariables

End Sub

0 个答案:

没有答案