change file path to look at a cell in the sheet

curtoliver68

New Member
Joined
Nov 19, 2024
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I have a form that has several modules that print screen to the desktop and modules that print a PDF to a determined path. I want to change that to look at a cell in the sheet so I can change between five different people and the folders they need to print to.

I want to change the path to look at cell V30 for the PDF and V31 for the Photos
 

Attachments

  • PDF.png
    PDF.png
    23.5 KB · Views: 3
  • photo.png
    photo.png
    34.3 KB · Views: 3

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
Hello,

For the first screenshot, as you did for the previous lines, you just need to do
VBA Code:
file_path=Range("V30").Value

For the second one, you need to write the full path to your photos folder
(by default on windows "C:\users\default\Pictures")

And you can refer to it in the same way, without using the shell shortcut :
VBA Code:
Path = Range("V31").Value & "\" & Range("V3").Value & ".jpg"
 
Upvote 0
so I tried the file_path=Range("V30").Value, and now it says publishing, but nothing happens. The old way with the path it showed saving and showed the path where it was saving.

There is an xlookup formula in the cell. Would that create any problems?
 
Upvote 0
No, formula is not a problem as long as the value in the cell is a correct path. It should be a full path, so something like "C:\users\default\Pictures".
 
Upvote 0
ha, I found the problem but am unsure what I need to do. I'm looking at cell V30 but it's on sheet19 not the current sheet
 
Upvote 0
Okay, be careful about the sheets, it is always recommended to reference sheets when referring to their cells to avoid those errors.

If the value is on the sheet named "sheet19", the correction is the following
VBA Code:
file_path=ThisWorkbook.Worksheets("sheet19").Range("V30").Value

I recommend you do the same correction on every one of the "Range" instruction you can find in the code. By default they all refer to the activesheet, which can change. When you explicitly write the sheet name (and the workbook), you avoid those errors.
 
Upvote 0
So i added the line and changed the cell which will be the new location but a debug error
 

Attachments

  • Debug1.png
    Debug1.png
    19 KB · Views: 1
Upvote 0
You did it correctly.

But with no information on the error I can not help you much. But I'm pretty sure your sheet name is not exactly "sheet19". Please copy the sheet name from the sheets list at the bottom and paste it in the code (between "").

If it is the correct name then it means your macro is not in the workbook where your sheets (and cells) are, in this case you should use

VBA Code:
Workbooks("name of your file.xlsm").Worksheets("name of the sheet").Range("address of the cell")

But double check the sheet name, the error is probably there.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,841
Messages
6,174,976
Members
452,596
Latest member
Anabaric

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