Import Macro and personal.xlsb

kmmsquared

New Member
Joined
Jan 7, 2011
Messages
33
I am new to macros and trying to get this to pull data from another file, but it only imports the data into my personal.xls sheet and not the active sheet. I have checked that it is under a general module and not a worksheet in the personal.xls, but can't get it to work.

Suggestions?


Sub GetDataFromClosedWorkbook()
Dim wb As Workbook
Application.ScreenUpdating = False ' turn off the screen updating
Set Thiswb = Workbooks.Open("FileName", True, True)
' open the source workbook, read only
With ThisWorkbook.Worksheets("Sheet1")
' read data from the source workbook
.Range("A1:C29").Formula = Thiswb.Worksheets("Sheet1").Range("A1:C29").Formula
End With
Thiswb.Close False ' close the source workbook without saving any changes
Set Thiswb = Nothing ' free memory
Application.ScreenUpdating = True ' turn on the screen updating
End Sub

Thanks
 
I have the code in my personal.xlsb so I can run it in any workbook, the problem is the import is done in the personal.xlsb and not whatever workbook is currently active, even if i run the macro from book1 the data will still import into my personal.xlsb
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
For instance:

Code:
Sub GetDataFromClosedWorkbook()
    Dim wbSource As Workbook, wbTarget As Workbook
    Application.ScreenUpdating = False    ' turn off the screen updating
    Set wbTarget = ActiveWorkbook
    Set wbSource = Workbooks.Open("FileName", True, True)
    ' open the source workbook, read only
    wbTarget.Worksheets("Sheet1").Range("A1:C29").Formula = wbSource.Worksheets("Sheet1").Range("A1:C29").Formula
    wbSource.Close 0    ' close the source workbook without saving any changes
    Set wbSource = Nothing: Set wbTarget = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,687
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top