Please can you cand my code for an error

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,
Please can you advise what ive done wrong with this line of code.
Basically the saved file is of pdf format, name is taken from cell B3 & date is taken from cell E3 but merged E3:K3


When using this line of code the file is saved as pdf & customers name all fine.
Rich (BB code):
strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & ".pdf"

However when i use this line of code which pulls the dat from cell E3 i just see an error message, unable to save.
Rich (BB code):
strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & " " & .Range("E3").Value & ".pdf"
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
After strFileName line put
Debug.Print strFileName
Stop

Do whatever you do to make the code run and when it stops, look in the immediate window of the code editor and see what the debug line prints there. Perhaps you'll see the problem. I can't see anything wrong with your code. Are you sure that E3 is the first cell of the merge?
 
Upvote 0
Further to what @Micron has asked, what exactly is the value in E3? are you sure that there are no characters that are illegal as filenames in it?
 
Upvote 0
Out at present so can’t do what Micron has advised

BUT.
I think Mark has pointed me in the right direction.
The userform has a date picker which sends the date to the cell E3
I think the answer will be it’s format possibly 16/03/2023 thus unable to use the / in the saved file name.

What should I now do to change the / to a - for it to then save.

Thanks.
I’m sure this is what the issue is.
 
Upvote 0
Try...
VBA Code:
Format(.Range("E3").Value, "dd-mm-yyyy")
 
Last edited:
Upvote 0
If you have illegal characters, that is why I suggested you review the concatenation result before trying to use it. It's trouble shooting 101.
 
Upvote 0
If you have illegal characters, that is why I suggested you review the concatenation result before trying to use it. It's trouble shooting 101.
Which is alright if the OP knows they are looking for illegal characters and knows what characters are illegal (in this case they did)
 
Upvote 0
Try...
VBA Code:
Format(.Range("B3").Value, "dd-mm-yyyy")
Do i need to put it here as if so im missing something

Rich (BB code):
Private Sub Worksheet_Activate()
Range("A1").Activate
Format(.Range("E3").Value, "dd-mm-yyyy")
End Sub
 
Upvote 0
Rich (BB code):
strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & " " & Format(.Range("E3").Value, "dd-mm-yyyy") & ".pdf"
 
Upvote 0
Please note the last post has been edited
 
Upvote 0

Forum statistics

Threads
1,215,365
Messages
6,124,512
Members
449,167
Latest member
jrob72684

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