Solved

Buttons to import sheet and data from one workbook to another

Posted on 2014-09-21
6
193 Views
Last Modified: 2014-09-26
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!!!!
0
Comment
Question by:Mcottuli
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40336876
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
0
 
LVL 1

Author Comment

by:Mcottuli
ID: 40336967
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?
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40336980
instead of sheet.name, put sheetname
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 1

Author Comment

by:Mcottuli
ID: 40337011
This time is does not error out, but the import does not happen. Attached are both files.
MasterWorkbookA.xlsx
ClientWorkbookA.xlsm
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40340931
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,
0
 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
ID: 40345841
Try This: (it's tested and it works)

Sub Button1_Click()
Dim directory As String, fileName As String, sheetName As String
Dim w As New Workbook, wh As New Worksheet
'Turn off screen updating and displaying alerts.
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'initialize variables
directory = "c:\test\"
fileName = "MasterWorkbookA.xlsx"
'open the main workbook
Set w = Workbooks.Open(directory & fileName)
sheetName = "Test"
Set wh = w.Worksheets(sheetName)
'get the sheet to copy depending on the button
w.Worksheets(sheetName).Copy after:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
w.Close
'Turn back screen updating to on
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

Open in new window


the problem in the code was that, once you open a workbook..
the worksheets instance object becomes that open workbook; the solution was to simply replace the destination syntax of worksheets... with thisworkbook.worksheets...
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question