Open file from the cell

ashani

Board Regular
Joined
Mar 14, 2020
Messages
182
Office Version
  1. 365
Platform
  1. Windows
Hi,

In my workbook - I have file path in my worksheet in Q8:S10 (merged cell) I would like to set the macro to open that path when user click on the button. It's a word document.

Also If the cells are empty than message box appear to say "Define Path".

Please can someone guide me.

Many thanks,
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

mrshl9898

Well-known Member
Joined
Feb 6, 2012
Messages
1,623
Try:

VBA Code:
Sub openfile()

    Dim wordapp
    Dim strFile As String

    strFile = Range("Q8").Value
    If Range("Q8") <> "" Then
    Set wordapp = CreateObject("word.Application")
    wordapp.Documents.Open strFile
    wordapp.Visible = True
    Else
    MsgBox "Define Path"
    End If
    
End Sub
 

ashani

Board Regular
Joined
Mar 14, 2020
Messages
182
Office Version
  1. 365
Platform
  1. Windows
thank you works perfectly.
quick question - the document opens in the background - is it possible to bring that to front so when click on the macro it opens up on the screen rather than in the background.
thanks once again.
 

mrshl9898

Well-known Member
Joined
Feb 6, 2012
Messages
1,623
Not sure how to do that sorry, I have seen code where you loop through all open windows. Maybe something there to bring one to the front. Try asking again in a new post.
 

AC PORTA VIA

Board Regular
Joined
Apr 9, 2016
Messages
74
Office Version
  1. 365
Platform
  1. Windows
try to add this line of code
VBA Code:
wordapp.Activate
after this line
Code:
wordapp.Visible = True
 

ashani

Board Regular
Joined
Mar 14, 2020
Messages
182
Office Version
  1. 365
Platform
  1. Windows
Thank you everyone- appreciate your help
 

Watch MrExcel Video

Forum statistics

Threads
1,122,454
Messages
5,596,228
Members
414,046
Latest member
mbeutler1203

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