Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何使VBA超链接正常工作?_Excel_Vba_Hyperlink - Fatal编程技术网

Excel 如何使VBA超链接正常工作?

Excel 如何使VBA超链接正常工作?,excel,vba,hyperlink,Excel,Vba,Hyperlink,我试图使用超链接,但它什么也没做。我想知道我需要改变什么来使用超链接 Sub RDB_Worksheet_To_PDF() Dim FileName As String Dim PONumber As String Dim FolderPath As String PONumber = Sheets("Purchase Order with Sales Tax").Cells(8, 6).Value FolderPath = "Z:\1.PRODUCTI

我试图使用超链接,但它什么也没做。我想知道我需要改变什么来使用超链接

Sub RDB_Worksheet_To_PDF()
    Dim FileName As String
    Dim PONumber As String
    Dim FolderPath As String

    PONumber = Sheets("Purchase Order with Sales Tax").Cells(8, 6).Value
    FolderPath = "Z:\1.PRODUCTION\1. PURCHASING\PO H 2012\"

    If ActiveWindow.SelectedSheets.Count > 1 Then
        MsgBox "There is more then one sheet selected," & vbNewLine & _
               "be aware that every selected sheet will be published"
    End If

    'Call the function with the correct arguments
    FileName = RDB_Create_PDF(ActiveSheet, FolderPath & PONumber, True, True)

    If FileName <> FolderPath & PONumber Then
        'Ok, you find the PDF where you saved it
        'You can call the mail macro here if you want
        MsgBox "Sweet! The PO has been saved as a PDF." & vbNewLine & _
               "Click on the PO Number in the PO Number WorkSheet to view."
    Else
        MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
               "Microsoft Add-in is not installed" & vbNewLine & _
               "There is no PO number selected" & vbNewLine & _
               "The path to Save the file in is not correct" & vbNewLine & _
               "You didn't want to overwrite the existing PDF if it exist"
    End If


    Sheets("PO Number").Select
    Range("A1").Select


    Set smvar = Cells.Find(What:=PONumber, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False)
       If Not smvar Is Nothing Then smvar.Activate

        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
            FolderPath & PONumber & ".pdf"
        Sheets("Purchase Order with Sales Tax").Select


End Sub
将RDB工作表分为PDF()
将文件名设置为字符串
像线一样暗的数字
将FolderPath设置为字符串
PONumber=张数(“含销售税的采购订单”)。单元格(8,6)。值
FolderPath=“Z:\1.生产\1.采购\PO H 2012\”
如果ActiveWindow.SelectedSheets.Count>1,则
MsgBox“选择了多张工作表”&vbNewLine&_
“请注意,将发布每个选定的工作表”
如果结束
'使用正确的参数调用函数
FileName=RDB\u Create\u PDF(ActiveSheet、FolderPath和PONumber、True、True)
如果文件名为FolderPath&PONumber,则
'好的,您可以找到保存它的PDF
'如果需要,可以在此处调用mail宏
MsgBox“好极了!采购订单已另存为PDF。”&vbNewLine&_
“单击要查看的订单号工作表中的订单号。”
其他的
MsgBox“无法创建PDF,可能原因:&vbNewLine&_
“未安装Microsoft加载项”&vbNewLine&_
“未选择采购订单编号”&vbNewLine&_
“保存文件的路径不正确”&vbNewLine&_
“如果现有PDF存在,您不想覆盖它”
如果结束
工作表(“采购订单编号”)。选择
范围(“A1”)。选择
设置smvar=Cells.Find(What:=PONumber,After:=ActiveCell,LookIn:=xlFormulas,LookAt_
:=xlPart,SearchOrder:=xlByRows,SearchDirection:=xlNext,MatchCase:=_
False,SearchFormat:=False)
如果不是smvar,则smvar.Activate为空
ActiveSheet.Hyperlinks.Add锚定:=选择,地址:=_
FolderPath&PONumber&“.pdf”
工作表(“含增值税的采购订单”)。选择
端接头

这对我很有用-适应环境

Sub Tester()

    Dim shtPO As Worksheet, smvar As Range

    Set shtPO = Sheets("Sheet1")

    Set smvar = shtPO.Cells.Find(What:="Hello", _
                 After:=ActiveCell, LookIn:=xlFormulas, _
                 LookAt:=xlPart)

    If Not smvar Is Nothing Then
       shtPO.Hyperlinks.Add Anchor:=smvar, Address:="C:\folder\folder2\file.pdf"
    End If

End Sub

无需选择/激活任何内容。

不确定我是否非常清楚该问题。。。 但请您先选择工作表,然后创建超链接

Sub createHyperLink()

 Sheets("Purchase Order with Sales Tax").Select

 ActiveSheet.Hyperlinks.Add Anchor:=Selection, _
 Address:="example.pdf", _
 ScreenTip:="This is the link file", _
 TextToDisplay:="Linked PDF"

End Sub

这将在名为“带增值税的采购订单”的工作表中的默认选定单元格中创建链接。

您尚未发布所有代码,因此我们无法知道您的代码中是否存在导致此问题的原因。我已发布了所有代码。是allIt,不在这里。您的第二个代码块没有出现在第一个代码块中,并且第一个代码块没有
End Sub
,因此它不能是所有代码。然后编辑您的问题。“这是超链接…”这句话应该像一条评论。它分解了你的代码,使它看起来像你在谈论的2部分。将注释从代码中移出或缩进@戴维哲门斯:我对编辑不会破坏这篇文章没有足够的信心。你所做的就是我所做的。你在单元格A1中有超链接吗?如果我想在不同的工作表中创建链接怎么办?我是否更改“含销售税的采购订单”?