Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Refering to the current workbook in a macro

I have a macro that I have written to open a certificate and dump information
into textboxes from the open excel workbook. The problem is the macro refers
to my template workbook so if I save it as a different name the macro code
breaks. How do you refere to the current open workbook instead of the
workbook name? This is the code that I am having trouble with. Thank you for
your help.


Sub NewCert()
'
' NewCert Macro
' Macro recorded 5/29/2007 by Tim Peter
'

'
Workbooks.Open Filename:= _
"I:\work\Engineering Data\Product Data\Nozzles\Forms\Certificate.xls"
ActiveWindow.Zoom = 250
ActiveChart.Shapes.AddTextbox(msoTextOrientationHo rizontal, 266.95,
265.57, _
35.39, 12.9).Select
Selection.Characters.Text = ""
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Selection.Formula = _
"'[Nozzle_Certificate_Form_20ft-Bell.xls]Data 20 cft Bell'!$K$2"
ActiveChart.Shapes.AddTextbox(msoTextOrientationHo rizontal, 345.53,
362.8, _
90.28, 18#).Select
Selection.Characters.Text = ""
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Refering to the current workbook in a macro

You can use ActiveWorkbook to refer to the current book. But since you are
opening the book in the macro that would not help with the issue of saving it
under a different name.

You can either assume the sheet you want to modify is open and the current
sheet or you can Application.Dialogs(xlDialogOpen).Show to allow them to
select the file.

Peter Richardson

"tpeter" wrote:

I have a macro that I have written to open a certificate and dump information
into textboxes from the open excel workbook. The problem is the macro refers
to my template workbook so if I save it as a different name the macro code
breaks. How do you refere to the current open workbook instead of the
workbook name? This is the code that I am having trouble with. Thank you for
your help.


Sub NewCert()
'
' NewCert Macro
' Macro recorded 5/29/2007 by Tim Peter
'

'
Workbooks.Open Filename:= _
"I:\work\Engineering Data\Product Data\Nozzles\Forms\Certificate.xls"
ActiveWindow.Zoom = 250
ActiveChart.Shapes.AddTextbox(msoTextOrientationHo rizontal, 266.95,
265.57, _
35.39, 12.9).Select
Selection.Characters.Text = ""
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Selection.Formula = _
"'[Nozzle_Certificate_Form_20ft-Bell.xls]Data 20 cft Bell'!$K$2"
ActiveChart.Shapes.AddTextbox(msoTextOrientationHo rizontal, 345.53,
362.8, _
90.28, 18#).Select
Selection.Characters.Text = ""
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to grab current workbook filename TR Young Excel Worksheet Functions 3 June 12th 09 12:41 PM
how can i get a macro in personal.xls to know my current workbook? [email protected] Excel Programming 2 August 3rd 06 09:23 PM
save workbook as current date using a macro ExcelJon Excel Discussion (Misc queries) 2 June 21st 06 03:05 AM
refering to a workbook name within vba DarrenWood[_5_] Excel Programming 4 July 1st 05 11:43 PM
Close current Workbook after calling macro in other Des Janke Excel Programming 4 August 7th 03 07:33 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"