PDA

View Full Version : Filepath to reference cell value



est
12-09-2019, 07:33 AM
Hi All,

I am running a macro from Excel, part of which opens a specified word document.

At the moment, the filepath for the said word document reads:

C:\Users\jeremy.watson\*****\*****\*****\*****.docm

The document exists as a shared document and therefore if sarah Jennings wants to run the macro, Jeremy.watson would need to be replaced with sarah.jennings!

I hope that makes sense... The half solution I have come up with is asking the user to enter their username into a cell - and then having the filepath refer to that cell to inform the filepath.

If the above makes any sense, could someone tell me if it is possible, and if so, what should my filepath look like if I want it to incorporate the value in cell D2 instead of having a fixed path that reads name.surname?

Thanks in advance for anyone's time!

Total Noob.

paulked
12-09-2019, 08:46 AM
Try:


Sub test()
Dim fPath As String, oShell As Object
Set oShell = CreateObject("Shell.Application").BrowseForFolder(0, "Please pick a folder", 0)
fPath = oShell.self.Path & "\*****\*****\*****\*****.docm"
MsgBox fpath
End Sub

est
12-12-2019, 04:35 AM
Try:


Sub test()
Dim fPath As String, oShell As Object
Set oShell = CreateObject("Shell.Application").BrowseForFolder(0, "Please pick a folder", 0)
fPath = oShell.self.Path & "\*****\*****\*****\*****.docm"
MsgBox fpath
End Sub





Hi Paulked,

Thank-you for your response!

Am I right in assuming you cannot refer to a cell when writing a path?

e.g. "C:\home" & "D2" & "\word.docm"

Thanks,

Erinc

大灰狼1976
12-12-2019, 09:57 PM
Maybe


"C:\home" & [D2] & "\word.docm"

--Okami

est
12-13-2019, 02:18 AM
Maybe


"C:\home" & [D2] & "\word.docm"

--Okami

Ah, it worked! So simple, thank-you!

Resolved.