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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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