macro that runs on startup

ajtilley

New Member
Joined
Jul 19, 2010
Messages
24
Hi

Is there vba code that i can put in an excel 2007 workbook so that when it run so that if macros are enabled or turned on it moves a shape from one position to another.

Thus if macros were enabled the shape would be at the bottom of the page or on a hidden sheet, but if the person enabled macros or they were enabled automaticaly when the sheet was run the shape would instantly move to the front page where it could be used?
 

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
You can use the Workbook_Open event which has to go in the ThisWorkbook module. In the VBE in the Project window double click ThisWorkbook and paste in

Code:
Private Sub Workbook_Open()
'
'code to move shape
'
End Sub
 

ajtilley

New Member
Joined
Jul 19, 2010
Messages
24
Thankl you, i thought so, does anyone know what code i should use to move a shape from one position to another?
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
I think I would just unhide it

Code:
Private Sub Workbook_Open()
Sheets("Front Page").Shapes("Rectangle 1").Visible = True
End Sub
 

ajtilley

New Member
Joined
Jul 19, 2010
Messages
24

ADVERTISEMENT

Excellent, thats much better

I assume if i add a Before-close option i can get it to dissapear when the document closes as well. Ready for the next time someone loads the document up.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Yes, and you'll need to save as well

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Front Page").Shapes("Rectangle 1").Visible = False
Me.Save
End Sub
 

roscoe

Well-known Member
Joined
Jun 4, 2002
Messages
1,007
I do the same thing as sometimes the file will be saved in a location that is not trusted and run by folks not familar with macros. I have a callout box pointing to the options button telling them to slect it and enable macros. If/when the macros are enabled, the code hides rather than moves it.

Code:
Private Sub Workbook_Open()
    Worksheets("data").Shapes("Rectangular Callout 1").Visible = False
End Sub

Private Sub Workbook_beforeClose(cancel As Boolean)
    Worksheets("data").Shapes("Rectangular Callout 1").Visible = True
End Sub
Like you said, just make sure you make it visible again at closing.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,721
Messages
5,513,025
Members
408,933
Latest member
frossen

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top