Open file from the cell

ashani

Active Member
Joined
Mar 14, 2020
Messages
345
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,
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
try to add this line of code
VBA Code:
wordapp.Activate
after this line
Code:
wordapp.Visible = True
 
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,546
Members
449,038
Latest member
Guest1337

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