View Single Post
 
Old 11-25-2011, 08:29 AM
tinfanide tinfanide is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Why it works but the macro is error in VB?

The macro runs well but when I press F5 in VB, it always returns "runtime error: 462" when it comes to the saveAs method.


Code:
Private Sub copytoWord_Click()
     
    Dim AppWord         As Word.Application
     
    Set AppWord = CreateObject("Word.Application")
    AppWord.Visible = True
    
    Sheets("Sheet1").Range("A1:B4").Copy
    AppWord.Documents.Add
  
    AppWord.Selection.Paste
     
    Application.CutCopyMode = False
     
     
   With ActiveDocument
   .SaveAs2 "C:\Users\Tin\Desktop\" & "Book1", wdFormatDocumentDefault
   End With
    
    Set AppWord = Nothing
    
     
End Sub
Reply With Quote