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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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