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
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Please run this macro and let us know the result in the MsgBox.

Code:
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
    MsgBox ThisWorkbook.Name
    Thiswb.Close False    ' close the source workbook without saving any changes
    Set Thiswb = Nothing    ' free memory
End Sub
 
Upvote 0
There you got your response/error.
 
Upvote 0
I do not mean that you should change your initial post, I just wanted to say that you should paste the code in a module in the correct workbook. Or change the code so that the output is done in a different file.
 
Upvote 0
I'm sorry for being so vague in the initial post, I need help changing the code so that the output is done in an active workbook. I am very new to macros!
 
Upvote 0
And the active workbook is the one you open with the code? Because that's what you'd have with your code.
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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