Open file from the cell

ashani

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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,213,506
Messages
6,114,025
Members
448,543
Latest member
MartinLarkin

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