PC Review


Reply
Thread Tools Rate Thread

Copy workbook without Macros

 
 
Robert
Guest
Posts: n/a
 
      15th Feb 2007
I'm having problems copying an excel workbook the way I want to.

I currently have a MasterCopy.xls with data on Sheet1 and all my
macros imported. I need to create a new workbook (I called it Junk
Test.xls) and copy the first sheet of MasterCopy.xls onto
JunkTest.xls. However, I don't want the new Junk test workbook to
have any of the VBA macro stuff in it. I can't figure out how to do
that. Here's a basic look at what I have:

Private Sub Workbook_Open()
Dim sDest As String
sDest = "C:\Documents and Settings\rb012653\Desktop"
Data_Mover.SaveCopy sDest
End Sub

~~~In my Data_Mover Module~~~~~
Public Sub SaveCopy(sDest As String)
Dim NewWB As Workbook
Set NewWB = Workbooks.Add(sDest & "\Junk Test.xls")
'I've tried lots of copy commands here without any luck.
End Sub

Whenever I try and open the new JunkTest.xls file I also get the
following error:
Runtime error '1004': Cannot access 'JunkTest.xls.' This is my first
time posting, so I appologize if it is in another thread. I've
searched all over and couldn't find anything to help me figure this
one out.

 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      15th Feb 2007
Your code is attempting to use sDest & "\Junk Test.xls" as template for a
newly created workbook. When call Add, if you pass parameter, it must the
name of an existing file that is used as a "template" (in the generic sense,
not necessarily in the "xlt" sense) for the newly create workbook. The
parameter is NOT the name of the file as which the newly create workbook
will be saved. Since sDest & "\Junk Test.xls" doesn't exist, Add blows up
with a file not found problem.

Instead, do something like

Set NewWB = Workbook.Add() ' no parameter
NewWB.SaveAs sDest & "\Junk Test.xls" ' save to disk

See www.cpearson.com/excel/vbe.htm for details and example code about how to
remove all existing VBA code from a workbook.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



"Robert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm having problems copying an excel workbook the way I want to.
>
> I currently have a MasterCopy.xls with data on Sheet1 and all my
> macros imported. I need to create a new workbook (I called it Junk
> Test.xls) and copy the first sheet of MasterCopy.xls onto
> JunkTest.xls. However, I don't want the new Junk test workbook to
> have any of the VBA macro stuff in it. I can't figure out how to do
> that. Here's a basic look at what I have:
>
> Private Sub Workbook_Open()
> Dim sDest As String
> sDest = "C:\Documents and Settings\rb012653\Desktop"
> Data_Mover.SaveCopy sDest
> End Sub
>
> ~~~In my Data_Mover Module~~~~~
> Public Sub SaveCopy(sDest As String)
> Dim NewWB As Workbook
> Set NewWB = Workbooks.Add(sDest & "\Junk Test.xls")
> 'I've tried lots of copy commands here without any luck.
> End Sub
>
> Whenever I try and open the new JunkTest.xls file I also get the
> following error:
> Runtime error '1004': Cannot access 'JunkTest.xls.' This is my first
> time posting, so I appologize if it is in another thread. I've
> searched all over and couldn't find anything to help me figure this
> one out.
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop down list using macros in a personal macros workbook jlcoop01 Microsoft Excel Programming 0 23rd Oct 2009 03:56 PM
Use VBA to copy macros from one workbook to another Dean@ERYC Microsoft Excel Programming 3 30th Apr 2008 04:37 PM
How to copy a workbook so the buttons run the macros? - Microsoft Excel Misc 4 15th May 2005 11:24 PM
Open workbook-macros enabled, opening another with macros George J Microsoft Excel Programming 5 17th Sep 2004 02:07 PM
Copy Macros and VB code from one workbook to another Dawn Microsoft Excel Programming 1 2nd Dec 2003 11:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:06 PM.