VBA Open file and convert to PDF

Cagey93

New Member
Joined
Apr 17, 2019
Messages
34
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
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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:
Upvote 0
Hello,

the file path is as follows which I have triple checked is correct [TABLE="width: 616"]
<tbody>[TR]
[TD="width: 616"]"\\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. [/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited by a moderator:
Upvote 0
Are the quotes included in the cell? If they are, remove them.
 
Last edited by a moderator:
Upvote 0
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.
 
Upvote 0
Does B10 contain the full path & filename?
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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