Basic Macro Question

Abhishek1988

New Member
Joined
Oct 22, 2018
Messages
27
Hi Everyone,

I have below code to insert documents into excel

Sub Insert_OLE_Object()

Worksheets("Sheet1").OLEObjects.Add Filename:="c:\temp\sample.pdf", Link:=False, DisplayAsIcon:=False, Left:=40, Top:=40, Width:=150, Height:=10
End Sub

I want to know how can i can run above code by clicking on button. Where i should put dis code in VBA?

Please help me in this
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
After drawing the button on your sheet, "Assign Macro" window will pop up, choose your Function ( Insert_OLE_Object()) from the list, or just click the New button from that window and paste your code inside that Sub:

Code:
Worksheets("Sheet1").OLEObjects.Add Filename:="c:\temp\sample.pdf",  Link:=False, DisplayAsIcon:=False, Left:=40, Top:=40, Width:=150,  Height:=10
 
Upvote 0
Still not sure I understand what are you looking for but, if you want to call multiple functions when the button is pressed, instead of assigning your button with an existing macro, you can call those functions as bellow:

Code:
Sub Button_Click() 
MyFunc1
MyFunc2
End Sub

Sub MyFunc1
MsgBox "This is MyFunc1" 
End Sub

Sub MyFunc2 
MsgBox "This is MyFunc2" 
End Sub

Replace MyFunc1 and MyFunc2 with your Function Names.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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