2014-10-07 106 views
0

我对此代码有问题。我试图弄清楚它是什么毛病此代码,但不能找到解决Cells.find错误91

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 

我在这部分

**Cells.Find(What:=PONumber, After:=ActiveCell, LookIn:=xlFormulas, LookAt _ 
     :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ 
     False, SearchFormat:=False).Activate** 

是不是因为我没有使用.activate或收到错误消息91我没有使用set =? 请让我知道我需要做什么。

干杯

+0

其余的代码?看起来不完整的信息。 – ZAT 2014-10-07 19:44:42

+0

其完整的信息 – Nzasianboy 2014-10-07 20:14:01

回答

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 
+0

谢谢你的评论,但我得到了另一个错误消息9在这部分PONumber =表(“采购订单与销售税”)。Cells(8,6)。Value – Nzasianboy 2014-10-07 20:04:57

+0

它是相同的cells.find错误91,或运行时错误'9'?如果是错误9检查您的工作表的名称(空间/等)。另外我假设代码位于“模块”中。也请提及您所有的错误 – Alex 2014-10-07 20:21:05

+0

我之前看到了cells.find错误91,之后我将代码更改为您建议的设置smavar =,然后我在表格中出现了错误9(“购买订单和销售税”)。 (8,6)。值 – Nzasianboy 2014-10-07 20:57:36