![]() |
#7
|
|||
|
|||
![]()
oh dear! I must be under the weather... so obvious that when I saw your reply I rolled my eyes as my own stupidity!
After sorting out a couple of minor errors of my own doing, I am stoked to report that the UserForm now does exactly what I need it to do and with the carryover into the spreadsheet so THANK YOU for your perseverance and tolerance for my lack of VBA skills. But (there is always a but!) I have now run into another issue that I am struggling with. Each of the individual Report template sheets, as you would have seen, have a command button to save the Report template as an .xlsm file. Part of the macro also copies information contained in two cells and uses that info as the majority of the file name. It also looks for "/", " / " and replaces it with "_" if they appear in either of the two cells so as not to muck up the file name and require the User to change them manually. Query 1 - is there a way to have the macro read a "/" in either of the two referenced cells and convert it to a "_" in the file name but leave it as "/" in the cell? The code for the command button, and different where necessary according to the worksheet names, is: Code:
Private Sub CommandButton1_Click() Sheet2.CommandButton1.BackColor = RGB(242, 242, 242) Dim fName As Variant Dim myCell As Range Dim myCharacterToReplace As String Dim myReplacementCharacter As String Set myCell = ThisWorkbook.Worksheets("Report template - Advanced").Range("L5") myCharacterToReplace = " / " myReplacementCharacter = "_" myCell.Value = Replace(Expression:=myCell.Value, Find:=myCharacterToReplace _ , Replace:=myReplacementCharacter) Set myCell = ThisWorkbook.Worksheets("Report template - Advanced").Range("L5") myCharacterToReplace = "/" myReplacementCharacter = "_" myCell.Value = Replace(Expression:=myCell.Value, Find:=myCharacterToReplace _ , Replace:=myReplacementCharacter) Set myCell = ThisWorkbook.Worksheets("Report template - Advanced").Range("H17") myCharacterToReplace = "/" myReplacementCharacter = "_" myCell.Value = Replace(Expression:=myCell.Value, Find:=myCharacterToReplace _ , Replace:=myReplacementCharacter) fName = Application.GetSaveAsFilename(InitialFileName:=Range("H17").Value & " Report" _ & Range("A1").Value & Range("L5").Value, FileFilter:="Excel Files (*.xlsm), *.xlsm" _ , Title:="Save As COMSEC Incident report as") If fName = False Then Exit Sub ActiveWorkbook.SaveAs filename:=fName, FileFormat:=52 End Sub Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Dim xFileName As String Dim myCell As Range Dim myCharacterToReplace As String Dim myReplacementCharacter As String Set myCell = ThisWorkbook.Worksheets("Report template").Range("L5") myCharacterToReplace = " / " myReplacementCharacter = "_" myCell.Value = Replace(Expression:=myCell.Value, Find:=myCharacterToReplace, Replace:=myReplacementCharacter) Set myCell = ThisWorkbook.Worksheets("Report template").Range("L5") myCharacterToReplace = "/" myReplacementCharacter = "_" myCell.Value = Replace(Expression:=myCell.Value, Find:=myCharacterToReplace, Replace:=myReplacementCharacter) Set myCell = ThisWorkbook.Worksheets("Report template").Range("H17") myCharacterToReplace = "/" myReplacementCharacter = "_" myCell.Value = Replace(Expression:=myCell.Value, Find:=myCharacterToReplace, Replace:=myReplacementCharacter) If SaveAsUI <> False Then Cancel = True xFileName = Application.GetSaveAsFilename(InitialFileName:=Range("H17").Value & Range("A1").Value & Range("L5") _ , FileFilter:="Excel Files (*.xlsm), *.xlsm", Title:="Save Report as") If xFileName <> "False" Then Application.EnableEvents = False ActiveWorkbook.SaveAs filename:=xFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled Application.EnableEvents = True End If End If End Sub I also tried referencing the three worksheets as an Array but that didn't work either. Query 2 - how, what, where have I gone wrong in the save routine.... and apologises for the longwinded ramble. Last edited by kiwimtnbkr; 06-10-2019 at 02:52 AM. Reason: clarified Save UI Cancel button happenings |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Option Buttons - linking and control | natelfo | Visio | 8 | 01-25-2024 02:01 AM |
Option buttons for multiple choice questions | ScottishPolarBear | Word | 4 | 12-02-2014 02:23 PM |
Display cells dependent on option buttons | inq80 | Excel | 0 | 09-01-2014 03:40 PM |
How do you achieve Falling letters? | PPT | PowerPoint | 0 | 04-21-2012 06:12 AM |
![]() |
JacobThomas | Word VBA | 1 | 11-02-2011 05:40 AM |