VBA Save As with period in name

Realtreegirl75

New Member
Joined
Aug 28, 2022
Messages
31
Office Version
  1. 365
Platform
  1. Windows
I'm working on creating a VBA that will save a document automatically based on information in the document. Here is the code:


Dim tdayName As String
Dim MPID As String
Dim numb As String
Dim tday As String


MPID = Range("O4").Text
numb = Range("C4").Text
tday = Range("H4").Text
tdayName = "SCP - " & MPID & " - " & numb & " - " & tday

MsgBox tdayName
Application.Dialogs(xlDialogSaveAs).Show tdayName



O4 is 123456
C4 is E.123456
H4 is 2022-10-30

The message box shows the correct name SCP - 123456 - E.123456 - 2022-10-30
The name won't come up in the save dialog box unless I remove the "." from cell C4. Is there anyway around this or will we just have to leave the period out when typing in the number in cell C4?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try to select the folder first.
Try one of these options:

VBA Code:
Sub test1()
  Dim tdayName As String, MPID As String
  Dim numb As String, tday As String
  Dim sPath As String
  
  MPID = Range("O4").Text
  numb = Range("C4").Text
  tday = Range("H4").Text
  tdayName = "SCP - " & MPID & " - " & numb & " - " & tday
  
  With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "Select Folder"
    If .Show <> -1 Then Exit Sub
    sPath = .SelectedItems(1)
    ActiveWorkbook.SaveAs Filename:=sPath & "\" & tdayName & ".xlsx", _
        FileFormat:=xlOpenXMLWorkbook
  End With
End Sub

VBA Code:
Sub test2()
  Dim tdayName As String, MPID As String
  Dim numb As String, tday As String
  Dim sPath As String
  
  MPID = Range("O4").Text
  numb = Range("C4").Text
  tday = Range("H4").Text
  tdayName = "SCP - " & MPID & " - " & numb & " - " & tday
  
  With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "Select Folder"
    If .Show <> -1 Then Exit Sub
    sPath = .SelectedItems(1)
    ActiveWorkbook.SaveCopyAs sPath & "\" & tdayName & ".xlsm"
  End With
End Sub
 
Upvote 0
I can't select the folder first because this is a form that will go out to around 50 people and they will all be saving it in different locations on their computers. I have this exact code working in a different form (without the E.123456) and it works great every time. And this works if I take the "." out of the E123456, I was just wondering if theres a way to be able to leave it in.
 
Upvote 0
So I asked a question that I thought might be another way to fix the issue and it got the desired results: Use a VBA to remove the period in the cell. The code used was this:

Excel Formula:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Exit if update is not to cell AC3
    If Intersect(Target, Range("AC3")) Is Nothing Then Exit Sub
   
'   Get rid of periods in entry
    Application.EnableEvents = False
    Range("AC3").Value = Application.WorksheetFunction.Substitute(Range("AC3").Value, ".", "")
    Application.EnableEvents = True

End Sub

And now everything works perfectly. Thanks!
 
Last edited by a moderator:
Upvote 0
Solution
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug. My signature block below has more details. I have added the tags in the previous post for you this time. 😊

BTW, rather than call out to the worksheet function Substitute to replace any dots, it would be more efficient to use vba's own function, Replace.
Rich (BB code):
Range("AC3").Value = Application.WorksheetFunction.Substitute(Range("AC3").Value, ".", "")
Range("AC3").Value = Replace(Range("AC3").Value, ".", "")
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,255
Members
449,075
Latest member
staticfluids

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