Share via

VBA - Data Import from external workbook

Anonymous
2022-07-05T15:56:53+00:00

Hello,

My goal is to import data from an external wb into a new sheet in the active wb so I may summarize the external pages. So far my VBA program looks like this:

Sub Get_Data_From_File()

*Dim FileToOpen As Variant* 

*Dim Openbook As Workbook* 

*Application.ScreenUpdating = False* 

*FileToOpen = Application.GetOpenFilename(Title:="Import Take-Off", FileFilter:="Excel Files(\*.xls\*),\*xls\*")* 

*If FileToOpen <> False Then* 

    *Set Openbook = Application.Workbooks.Open(FileToOpen)* 

    *Openbook.Sheets(Template).Range("C1:V189").Copy* 

    *ThisWorkbook.Worksheets("sheet1").Range("A1").PasteSpecialxlPasteValues* 

    *Openbook.Close False* 

*End If* 

*Application.ScreenUpdating = True* 

End Sub

The error I receive is one of two: Run-time error 9 (which I can fix) and run-time error 438. When error 438 appears the program has opened the external wb in the background but fails to copy the data into the new wb and new wb sheet. I could be missing something incredibly obvious here since I am new.

Microsoft 365 and Office | Excel | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2022-07-05T16:05:39+00:00

    Change

    ThisWorkbook.Worksheets("sheet1").Range("A1").PasteSpecialxlPasteValues

    to

    ThisWorkbook.Worksheets("sheet1").Range("A1").PasteSpecial xlPasteValues

    with a space between PasteSpecial and xlPasteValues

    Was this answer helpful?

    0 comments No comments