PC Review


Reply
Thread Tools Rate Thread

Button looses Macro setting when running Macro

 
 
Dule
Guest
Posts: n/a
 
      7th Oct 2009
The code below was intended to export a sheet from Excel into a new workbook
when a button is entered, then save and close the new workbook and return to
the original workbook.

This code ran without issue in Excel 2003 but with 2007 after the new book
is made, saved and closed, the macro button in the original book and all the
buttons with macros assigned in the orginal book dont work.

It seems that each button thinks their macro is associated with the new
workbook that was created and the path to the macro in the original was
changed. I have tried to find an answer or a workaround for this but have
had no luck.

Would anyone be able to offer me any advice?

Dule

Sub ExportSheet1()
'
ThisWorkbook.Activate
Sheets("Sheet1").Select

Sheets("Sheet1").Copy Before:=Sheets("Sheet1")

Sheets("Sheet1 (2)").Select
Sheets("Sheet1 (2)").Move
Range("B1").Select

SaveExportedSheet1
ThisWorkbook.Activate

End Sub

Sub SaveExportedSheet1()

fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xlsm), *.xlsm")

If fileSaveName <> False Then
ActiveWorkbook.Save
ActiveWorkbook.Close
Else: Cancel = True

End If

End Sub
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      7th Oct 2009
Try these changes

Sub ExportSheet1()

Dim newbk as variant

set oldbk = thisworkbook
' with oldbk
'create new workbook with one sheet
.Sheets("Sheet1").Copy
end with

set newbk = activeworkbook

Savebk(Newbk)

End Sub

Sub SaveExportedSheet1(Newbk)

fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xlsm), *.xlsm")

If fileSaveName <> False Then
newbk.Save
newbk.Close

End If

End Sub


"Dule" wrote:

> The code below was intended to export a sheet from Excel into a new workbook
> when a button is entered, then save and close the new workbook and return to
> the original workbook.
>
> This code ran without issue in Excel 2003 but with 2007 after the new book
> is made, saved and closed, the macro button in the original book and all the
> buttons with macros assigned in the orginal book dont work.
>
> It seems that each button thinks their macro is associated with the new
> workbook that was created and the path to the macro in the original was
> changed. I have tried to find an answer or a workaround for this but have
> had no luck.
>
> Would anyone be able to offer me any advice?
>
> Dule
>
> Sub ExportSheet1()
> '
> ThisWorkbook.Activate
> Sheets("Sheet1").Select
>
> Sheets("Sheet1").Copy Before:=Sheets("Sheet1")
>
> Sheets("Sheet1 (2)").Select
> Sheets("Sheet1 (2)").Move
> Range("B1").Select
>
> SaveExportedSheet1
> ThisWorkbook.Activate
>
> End Sub
>
> Sub SaveExportedSheet1()
>
> fileSaveName = Application.GetSaveAsFilename( _
> fileFilter:="Excel Files (*.xlsm), *.xlsm")
>
> If fileSaveName <> False Then
> ActiveWorkbook.Save
> ActiveWorkbook.Close
> Else: Cancel = True
>
> End If
>
> End Sub

 
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
Stop running macro button, like Ctrl-Break button h2fcell Microsoft Excel Programming 8 23rd Jan 2009 04:01 PM
Re: Stop running macro button, like Ctrl-Break button Dave Peterson Microsoft Excel Programming 1 22nd Jan 2009 05:23 PM
Re: Stop running macro button, like Ctrl-Break button Ronald R. Dodge, Jr. Microsoft Excel Programming 0 22nd Jan 2009 04:59 PM
Running a Macro through a button vs. VBA =?Utf-8?B?YWRhbWJ1c2g0MjQyQGhvdG1haWwuY29t?= Microsoft Excel Misc 2 31st Aug 2007 08:00 PM
excel to html looses button and macro, why? =?Utf-8?B?S2VsbHkgTWF5bw==?= Microsoft Excel Misc 0 7th Oct 2005 07:09 PM


Features
 

Advertising
 

Newsgroups
 


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