Link to home
Start Free TrialLog in
Avatar of Mcottuli
McottuliFlag for United States of America

asked on

Buttons to import sheet and data from one workbook to another

I need a button (macro) to import/copy the contents of MasterWorkbookA , sheet2 to ClientWorkbookA, sheet2 (The button must be initiated by ClientWorkBookA). Eventually there will be 12 buttons on sheet1, each button will update a different sheet from master to client (appearing as a table of contents). The "MasterWorkbookA" is a spreadsheet with 12 different sheets (Each sheet with own button) updated by a supervisor, an admin should be able to open ClientWorkBookA which has nothing other than sheet one containing these buttons the first time it is opened. They look at the table of contents, choose a button, click on it, and it should then create the sheet with the identical name from MasterWorkbookA within ClientWorkBookA with the identical data. It is also important that any subsequent clicks on that particular button will fail because it has already been imported once. In other words, if the sheetname already exists in ClientWorkbookA than an import would fail. Thank you very much, If you can give me info for one button I can replicate for additional buttons. Thank you very much for your help!!!!
Avatar of Dany Balian
Dany Balian
Flag of Lebanon image

Try Something like this: (modified the code to suit ur needs, but code is not tested)

Dim directory As String, fileName As String, sheetName as String
'Turn off screen updating and displaying alerts.
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'initialize variables
directory = "c:\test\"
fileName = "MasterWorkbookA.xls"
'open the main workbook
Workbooks.Open (directory & fileName)
'get the sheet to copy depending on the button
sheetname="sheet2"
Workbooks(fileName).Worksheets(sheet.Name).Copy after:=Worksheets(Worksheets.count)
Workbooks(fileName).Close
'Turn back screen updating to on
Application.ScreenUpdating = True
Application.DisplayAlerts = True

Open in new window


Code Source: import sheets using excel

hope this helps
Avatar of Mcottuli

ASKER

Thank you for your help. I am running the button from ClientWorkbookA.xlsx. (Updated the  When I attempt to run it I get Run-Time error '424' Object Required. Hit Debug and get line 12 lighting up yellow. Any thoughts?
instead of sheet.name, put sheetname
This time is does not error out, but the import does not happen. Attached are both files.
MasterWorkbookA.xlsx
ClientWorkbookA.xlsm
i am currently overseas, and i only have my mac with me..
will try to check them for you when i get back home tomorrow!
regards,
ASKER CERTIFIED SOLUTION
Avatar of Dany Balian
Dany Balian
Flag of Lebanon image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial