Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default auto run a macro

Hello,

I wanted to create a macro to generate a unique number that can be used as a
"qute number".

My spreadsheet has a "now function" in it. My macro coverts this function
to a number format with four decimal points. So everytime I open the
spreadsheet it generates a new number.

I want the macro to work in the quote spreadsheet but be disabled once the
file has been saved to a new name.
I thought this would happen if I saved the macro in the "this workbook" but
when I save the file to a new name then close all workbooks and open the
saved file the quote number changes which does not help me.

I am using version 2003 with Office XP Professional

Is there a way to make this macro work on just the one spreadsheet?

thank you for your time

m


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default auto run a macro


hi m,

Here's an example with two possible (untested!) approaches with one
commented out - nb, you'll have to change the strings as needed...



VBA Code:
--------------------


Option Explicit
Private Sub Workbook_Open()
With ThisWorkbook
' If .FullName = "C:\Users\Robert\Documents\Excel\Excel Forum.com\Blah.xls" Then
If .Name = "Blah.xls" Then
'change quote number
With .ActiveSheet.Range("a1")
.FormulaR1C1 = "=NOW()"
.Calculate
.Value = .Value
.NumberFormat = "0.0000"
End With
Else
'do nothing
End If
End With
End Sub
--------------------




hth
Rob


--
broro183

Rob Brockett. Always learning & the best way to learn is to
experience...
------------------------------------------------------------------------
broro183's Profile: 333
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=194201

http://www.thecodecage.com/forumz

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default auto run a macro

Broro 183,

thank you for your help with this. Your approach worked perfectly using the
full name approach.


"broro183" wrote in message
...

hi m,

Here's an example with two possible (untested!) approaches with one
commented out - nb, you'll have to change the strings as needed...



VBA Code:
--------------------


Option Explicit
Private Sub Workbook_Open()
With ThisWorkbook
' If .FullName = "C:\Users\Robert\Documents\Excel\Excel
Forum.com\Blah.xls" Then
If .Name = "Blah.xls" Then
'change quote number
With .ActiveSheet.Range("a1")
.FormulaR1C1 = "=NOW()"
.Calculate
.Value = .Value
.NumberFormat = "0.0000"
End With
Else
'do nothing
End If
End With
End Sub
--------------------




hth
Rob


--
broro183

Rob Brockett. Always learning & the best way to learn is to
experience...
------------------------------------------------------------------------
broro183's Profile: 333
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=194201

http://www.thecodecage.com/forumz



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default auto run a macro


Thanks for the feedback - I'm pleased I could help :)

Rob


--
broro183

Rob Brockett. Always learning & the best way to learn is to
experience...
------------------------------------------------------------------------
broro183's Profile: 333
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=194201

http://www.thecodecage.com/forumz

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
Sub Macro vrs Function Macro Auto Start Pat Excel Discussion (Misc queries) 7 June 6th 07 09:53 PM
Run Auto Macro only once Jim D Excel Worksheet Functions 2 May 23rd 07 11:37 PM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
Auto-run macro after auto-query refresh (Excel2000,sr1) Bill Cufflin Excel Programming 3 June 29th 06 03:30 AM
Auto Run Macro chris6562[_3_] Excel Programming 1 November 4th 04 06:57 PM


All times are GMT +1. The time now is 06:20 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"