VBA Open file and convert to PDF

Cagey93

New Member
Joined
Apr 17, 2019
Messages
28
Hello, a real novice here so excuse the probably simple question but I cannot locate an answer.

I have a master workbook which contains lots of file paths to other workbooks. These locations change every month so to get around it I have a sheet which automatically updates the file paths each month.

However I am struggling to get VBA to read that file path which is specified in the cell.

This is a smaller example but I have specified B10 and B11 as the path to open as they will always change but what code do I need to do which say Open "filepath1"

Sub Convert()


Dim filepath1 As String
Dim filepath2 As String


filepath1 = Range("B10").Value
filepath2 = Range("B11").Value

Workbooks.Open (filepath1)


End Sub
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

BlueAure

New Member
Joined
May 21, 2019
Messages
46
Hi Cagey93,

This code works for me. What do the values of those cells look like? It should be a simple file path to the worksheet you want to open. Example:

C:\Users\[USER_HERE]\Downloads\excel\New Microsoft Excel Worksheet.xlsx

No quotes or anything in the cell.
 
Last edited by a moderator:

Cagey93

New Member
Joined
Apr 17, 2019
Messages
28
Hello,

the file path is as follows which I have triple checked is correct
"\\companyname\Treasury\D&I\MACRO TEST\Excel 1\April\TESTERApril.xlsx"

obviously the company name is an actual name but I cant post that on here.

<tbody>
</tbody>
 
Last edited by a moderator:

BlueAure

New Member
Joined
May 21, 2019
Messages
46
Are the quotes included in the cell? If they are, remove them.
 
Last edited by a moderator:

Cagey93

New Member
Joined
Apr 17, 2019
Messages
28
No they aren't sorry I just put that to highlight the that from the rest of the reply. I have tested the file path is correct by copying it into an explorer window and it loads it no problem.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
41,159
Office Version
365
Platform
Windows
Does B10 contain the full path & filename?
 

Cagey93

New Member
Joined
Apr 17, 2019
Messages
28
Solved it silliest mistake I had moved it to another cell and didn't update the cell it was looking at, been staring at it so long but missed the obvious one.
 

Watch MrExcel Video

Forum statistics

Threads
1,099,934
Messages
5,471,619
Members
406,772
Latest member
imega

This Week's Hot Topics

Top