如何在Excelmacros编辑器中使用variables

我是新来的Excel编程,并正在做我的第一个程序。 我在调用函数中使用variables时遇到了麻烦(我认为它们被称为函数!),麻烦的是,我不认为variables正在我的函数中进行扩展,有人可以帮我解决它。

Sub HyperLinkReplace() Dim MyPath As String MyPath = Environ("UserProfile") & "\Games\" 'MsgBox "MyPath: value is " & MyPath Call ReplaceHyperlinkURL("C:\Users\Kids\Games\", "& MyPath &") End Sub Public Sub ReplaceHyperlinkURL(FindString As String, ReplaceString As String) Dim LinkURL, PreStr, PostStr, NewURL As String Dim FindPos, ReplaceLen, URLLen As Integer Dim MyDoc As Worksheet Dim MyCell As Range On Error GoTo ErrHandler Set MyDoc = ActiveSheet For Each MyCell In MyDoc.UsedRange If MyCell.Hyperlinks.Count > 0 Then LinkURL = MyCell(1).Hyperlinks(1).Address FindPos = InStr(1, LinkURL, FindString) If FindPos > 0 Then 'If FindString is found ReplaceLen = Len(FindString) URLLen = Len(LinkURL) PreStr = Mid(LinkURL, 1, FindPos - 1) PostStr = Mid(LinkURL, FindPos + ReplaceLen, URLLen) NewURL = PreStr & ReplaceString & PostStr MyCell(1).Hyperlinks(1).Address = NewURL 'Change the URL End If End If Next MyCell Exit Sub ErrHandler: MsgBox ("ReplaceHyperlinkURL error") End Sub 

我在上面做错了什么?

谢谢

更改Call ReplaceHyperlinkURL("C:\Users\Kids\Games\", "& MyPath &")Call ReplaceHyperlinkURL("C:\Users\Kids\Games\", MyPath) Call ReplaceHyperlinkURL("C:\Users\Kids\Games\", "& MyPath &")

MyPath已经是一个variables,用引号括起来使它成为一个string文字。