A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
Change
OpenBook.Application.Run("ImportData()")
to
Application.Run "'" & OpenBook.Name & "'!ImportData"
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Good afternoon!
I am hoping to obtain some assistance.
I tried looking online, but can't find any reference to the solution I'm trying to develop. I have a set of data I want to run through a template (which uses RegEx to clean, sort, and extract data) and then copy and paste to the current workbook. Ordinarilly I'd try to do it all in one step (i.e. import raw data and clean in the destination workbook), however the size of the data is signficiant and cleaning the data after import appears to be too cumbersome for Excel. Therefore, the only other option is to run it through a template and paste as values into the destination workbook.
Both the macro in the destination workbook and the macro in the template work, but I'm trying to figure out how to
1). a static file (the template)
2). run the import macro within the template
3). copy the data from the template
4). paste as values to the destination workbook
I can get to step 2, and Steps 3 and 4 are a breeze. But I just don't know specifically what syntax to use.
I was trying to use:
Dim FileToOpen As Variant
Dim OpenBook as Workbook
Dim sh as Worksheet
Dim sh2 as worksheet
Dim lastERow as long
Dim lastERow2 as long
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename
If FileToOpen <> False Then
Set sh = ThisWorkbook.Worksheets(3)
sh.showalldata
lastERow = sh.Range("A" & sh.Rows.Count).End(xlUp).Offset(1,0).Row
Set OpenBook=Application.Workbooks.Open(FileToOpen)
Set sh2 = OpenBook.Worksheets(1)
lastERow2 = sh2.Range("A" & sh2.Rows.Count).End(xlUp).Offset(1,0).Row
OpenBook.Application.Run("ImportData()")
sh2.Range("A2:W" & lastERow2).copy
sh.Range("A2:W" & lasteERow).pastespecial xlpastevalues
OpenBook.Application.CutCopyMode = False
OpenBook.Close False
Application.ScreenUpdating = True
End If
End Sub
Any ideas?
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
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.
Answer accepted by question author
Change
OpenBook.Application.Run("ImportData()")
to
Application.Run "'" & OpenBook.Name & "'!ImportData"
Thank you!!
This worked like a charm!!!
Omg is it really that easy?!
As soon as I get back to th office tomorrow I'll try it!!