小编den*_*enn的帖子

VBA InStr始终返回0

我正在使用Excel 2010并尝试创建一个函数,它将替换工作表中的部分链接,具体取决于用户输入.更具体我试图替换链接以匹配用户Dropbox位置.

这是我到目前为止的代码

Private Sub CommandButton1_Click()

Dim DropboxFolder As String
Dim SearchFor As String
Dim SearchPos As Integer

SearchFor = "Dropbox"

With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
On Error Resume Next
DropboxFolder = .SelectedItems(1)
For Each theHyperLink In ActiveSheet.Hyperlinks
  SearchPos = InStr(0, SearchFor, theHyperLink.Address, vbBinaryCompare)
  theHyperLink.Address = DropboxFolder
  Next
Err.Clear
On Error GoTo 0
End With

End Sub
Run Code Online (Sandbox Code Playgroud)

我已经尝试了调试代码,并添加了一个断点

SearchPos = InStr(0, SearchFor, theHyperLink.Address, vbBinaryCompare) 
Run Code Online (Sandbox Code Playgroud)

SearchFor "Dropbox" 和TheHyperLink.Address是"..\Dropbox\Salgdanmarks Salgsakademi\1\Ny Microsoft Word Document.docx"

但SearchPos设置为 0

我究竟做错了什么?

excel vba excel-vba

2
推荐指数
1
解决办法
2378
查看次数

标签 统计

excel ×1

excel-vba ×1

vba ×1