我想在单元格()中使用变量。公式

I want to use variables in cells (). formula

Shape.Cells ("something")。公式 = XXX 我想在 VBA 上输入一个变量

在 Cells.Formula 中,与 VBA 开头的文件不同 我想输入在 VBA 中定义的变量值(此处为字符串“1.0.0”)

相关部分的代码

Sub Input_Version_Information(ByVal VSSXpath As String)
    version_str =  "1.0.0"        
    For Each vssxMaster In vssxMasters
        vssxMaster.Shapes.Item(1).Cells("Prop.Version").Formula = version_str                
    Next
End Sub

所有代码

Sub Input_Version_Information(ByVal VSSXpath As String)
    Dim vsoApp As Visio.Application    
    Dim vssxDoc As Visio.Document
    Dim vssxMasters As Visio.Masters
    Dim vssxMaster As Visio.Master
    Dim FileName As String
    Dim version_str As String        
    Set vsoApp = CreateObject("Visio.Application")
    Call vsoApp.Documents.OpenEx(VSSXpath, visOpenRW)
    Set vssxDoc = vsoApp.Documents.Item(1)
    Set vssxMasters = vssxDoc.Masters    
    FileName = Dir(VSSXpath)
    FileName = Replace(FileName, ".vssx", "")    
    version_str = Mid(FileName, InStr(FileName, "v") + 1, Len(FileName))
        
    For Each vssxMaster In vssxMasters
        vssxMaster.Shapes.Item(1).Cells("Prop.Version").Formula = version_str                
    Next
    
    vssxDoc.Save    
    vssxDoc.Close
    vsoApp.Quit

    End Sub

Sub test_update()
    test_vssx_file = ”Flowchart_v1.0.0.vssx"
    Call Input_Version_Information(test_vssx_file)

End Sub

如果您需要将单元格值用作字符串,则必须使用语法

vssxMaster.Shapes.Item(1).Cells("Prop.Version").Formula = chr(34) & version_str & chr(34)

或三引号

vssxMaster.Shapes.Item(1).Cells("Prop.Version").Formula = """7.40"""

PS Topic with same question,抱歉我今天找不到M$FT官方资源的超链接…