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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Exceladd1ct

Board Regular
Joined
Feb 10, 2019
Messages
76
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

Abhishek1988

New Member
Joined
Oct 22, 2018
Messages
27
ADVERTISEMENT
Thanks for response. by doing this we are just copy that code into button but can i link both the SUB?
 
Upvote 0

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,651
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
What do you mean by both the SUB ???
 
Upvote 0

Exceladd1ct

Board Regular
Joined
Feb 10, 2019
Messages
76
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,195,849
Messages
6,011,955
Members
441,657
Latest member
Diupsy

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
Top