Advertisement

04.03.2008 at 09:56AM PDT, ID: 23293436
[x]
Attachment Details

From Access VBA Copy an Excel Sheet to a different Excel Workbook, Values Only

Asked by Hubbsjp21 in Microsoft Excel Spreadsheet Software

I have a button on a form that runs a query with a date on the form being used as criteria in the query.  I also have an Excel Woorkbook containing a sheet that is linked to the query, and a pivot table taken from the linked sheet.

What I am trying to accomplish is this:

Open the Excel file from the form so the query has access to the date.  (I have accomplished this)
Copy the two sheets from the "Main" file to a newly named Excel file.  I only want the VALUES from the linked sheet as I don't need to keep the link.  The copied sheet with the pivot table should have no problem referring to the "Values only" spreadsheet.

I have learned how to copy a sheet to it's own workbook, but not to another workbook.  I have reasearched and found some valuable stuff on EE, but my lack of knowledge in Excel has left me wanting.  I am attaching the code to show you how far I have gotten.

The error I get is "Method 'Copy' of object '_Worksheet' failed" at the last line of the attached snippet.

So, FIRST, I have not acomplished copying the worsheet at all, and SECOND, I have not accomplished copying the "Values Only" of the spreadsheet.  I realize they will probably be the same step, but I was learning as I went, and could go no further.

Thanks . . HubbsStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
Dim xltmp As New Excel.Application
Dim wks1 As Excel.Worksheet
Dim wks2 As Excel.Worksheet
Dim wbkSource As Excel.Workbook
 
'Dim xlObj As Object
Dim xlApp As Excel.Application
Dim wbkNew As Excel.Workbook
Dim wbkTarget As Excel.Workbook
Dim wks3 As Excel.Worksheet
 
txtNameEnd = Format(Now(), "mmddyy_hh_nn_ss")
 
'Set xlObj = CreateObject("excel.application")
Set xlApp = New Excel.Application
xlApp.Visible = False
Set wbkNew = xlApp.Workbooks.Add
xlApp.ActiveWorkbook.SaveAs "P:\Reporting\ActivityReports\VCC_ActivityRpt_XL_" & Forms!frmReports.txtNameEnd & ".xls"
Set wbkTarget = xlApp.Workbooks.Open("P:\Reporting\ActivityReports\VCC_ActivityRpt_XL_" & Forms!frmReports.txtNameEnd & ".xls")
'xlApp.Visible = True
 
Set wbkSource = xltmp.Workbooks.Open("P:\Reporting\ActivityReports\Template\VCC_Activity_Report_Main.xls")
'xltmp.Visible = True
 
Set wks1 = wbkSource.Sheets("Sheet1")
Set wks2 = wbkSource.Sheets("Summary")
'Set wks3 = wbkTarget.Sheets("Sheet1")
 
wks1.Copy Before:=wbkTarget.Sheets("Sheet1")
[+][-]04.03.2008 at 01:56PM PDT, ID: 21276884

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Excel Spreadsheet Software
Sign Up Now!
Solution Provided By: rorya
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.03.2008 at 03:14PM PDT, ID: 21277463

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 02:43AM PDT, ID: 21280046

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 06:48AM PDT, ID: 21281587

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 07:04AM PDT, ID: 21281793

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.04.2008 at 07:51AM PDT, ID: 21282326

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 07:59AM PDT, ID: 21282448

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.04.2008 at 08:39AM PDT, ID: 21282872

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628