Macro runs when workbook opens

Learn_VBA

New Member
Joined
Oct 9, 2017
Messages
25
How do I change this code, so that the macro runs when the workbook opens?
Code:
Sub InsertMap_Click()

 'Updateby Extendoffice 20161116
 Dim Pshp As Shape
 Dim xRg As Range
 Dim xCol As Long
 On Error Resume Next
 Application.ScreenUpdating = False
 Set Rng = ThisWorkbook.Sheets("Executive Summary").Range("A39")
 filenam = Rng
 Range("C40").Select
 ThisWorkbook.Sheets("Executive Summary").Pictures.Insert(filenam).Select
 Set Pshp = Selection.ShapeRange.Item(1)
 If Pshp Is Nothing Then GoTo lab
 With Pshp
 .Name = "Membership Map"
 .LockAspectRatio = msoFalse
 .width = 600
 .height = 600
' .Top = xRg.Top + (xRg.height - .height) / 2
' .Left = xRg.Left + (xRg.width - .width) / 2
 End With
lab:
 Set Pshp = Nothing
 Range("C40").Select
 Application.ScreenUpdating = True
 End Sub
 
Last edited by a moderator:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Move the code to the ThisWorkbook module and replace the declaration line with this:

Code:
Private Sub Workbook_Open()

and add this line to the beginning:

Code:
ThisWorkbook.Sheets("Executive Summary").Select
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,825
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top