我的代码有问题。我试图弄清楚这个代码有什么问题,但找不到解决方案
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
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
我在本部分中收到错误消息91
**Cells.Find(What:=PONumber, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate**
是因为我没有使用.activate或者我没有使用set =? 请让我知道我需要做什么。
干杯
答案 0 :(得分:1)
基本上你正在尝试找到单元格并同时激活它,如果没有找到,将提示你提到的错误。您可以先尝试找到它然后激活:
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