Open file based on Cell Information

Randy N

New Member
Joined
Oct 7, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi All,
I am new to Macros and am having an issue trying to insert a jpg in to my workbook. I named my files based on information that I gather in my workbook. I sell steel and it has a Certification that is a jpg. I want to open the file and print it based on the Grade Size and Heat as well as the day I received it. I narrowed down the macro to just the inserting jpg part.

Sub PullCert()
'
'This sub opens cert jpg based on Sheet "Table" Cell "AE6'"
Dim FN As String
FN = Worksheets("Table").Range("AE6").Value

'Here is the value of Cell AE6 - C-20813640 1038-295-02 09-29-22.jpg
'Insert worksheet for picture ("Summary" is another sheet in my workbook)
Sheets("Summary").Select
Sheets.Add

'Open jpg File name, based on value of cell value in Worksheet "Table" cell "AE6"
'I defined FN above using FN =
ActiveSheet.Pictures.Insert("Z:\SCANCERTS\FN").Select
End Sub

For some reason, it will not insert the jpg using the filepath with FN.
If I copy the value in AE6, and paste in where the FN is in the macro above... ("Z:\SCANCERTS\FN").Select
it works. I think the problem lays in naming the FN or in the ("Z:\SCANCERTS\FN").Select command.

I have been trying to figure this out for hours! Can someone help me? Would really appreciate it! I know it is something really easy...but I can't see it!

Thanks,
Randy
 

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
You need your FN variable outside of the quotes. Try replacing this:
ActiveSheet.Pictures.Insert("Z:\SCANCERTS\FN").Select

with this:
ActiveSheet.Pictures.Insert("Z:\SCANCERTS\" & FN).Select
 
Upvote 0
Hi Candyman8019,
Thanks for your input but that didn't work! I tried changing the Filepath as well to below. Still did not work!
Any other suggestions?
Thanks,
Randy

Sub PullCert()
'
'This sub opens cert jpg based on Sheet "Table" Cell "AE6'"
Dim FN As String
Dim FilePath as String

FN = Worksheets("Table").Range("AE6").Value
FilePath = "Z:\SCANCERTS\"

'Here is the value of Cell AE6 - C-20813640 1038-295-02 09-29-22.jpg
'Insert worksheet for picture ("Summary" is another sheet in my workbook)
Sheets("Summary").Select
Sheets.Add

'Open jpg File name, based on value of cell value in Worksheet "Table" cell "AE6"
'I defined FN above using FN =
ActiveSheet.Pictures.Insert(FilePath & FN).Select
End Sub
 
Upvote 0
Okay, try this. I've tested it on my pc and it works:
VBA Code:
Sub PullCert()
'
'This sub opens cert jpg based on Sheet "Table" Cell "AE6'"
Dim FN As String
FN = Worksheets("Table").Range("AE6").Value

'Here is the value of Cell AE6 - C-20813640 1038-295-02 09-29-22.jpg
'Insert worksheet for picture ("Summary" is another sheet in my workbook)
Sheets.Add
activesheet.name = FN

'Open jpg File name, based on value of cell value in Worksheet "Table" cell "AE6"
'I defined FN above using FN =
ActiveSheet.Pictures.Insert("Z:\SCANCERTS\" & FN)
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,016
Messages
6,122,700
Members
449,092
Latest member
snoom82

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