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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

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
42,509
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,102,105
Messages
5,484,715
Members
407,464
Latest member
Halaseh

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top