2014-10-07 72 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