![]() |
Replace character in string, not document
Hello all.
I have a macro in which I save the document creating the filename based on selected text in the document. However in some cases, the selected text looks like "995451/U." Obviously I cannot save using this name. I would like to convert this to "995451-U" for saving purposes only but NOT in the document. How can I do this? Thanks, KS |
Replace character in string, not document
if the format is always the same (six numbers, slash, letter) you could
use Dim MyFileName as Variant Dim SelectedText as Variant SelectedText = 'wherever that cell/text is MyFileName = Left(SelectedText, 6) & "-" & Right(SelectedText, 1) ActiveDocument.SaveAs: MyFileName this is not tested & may contain errors (i'm no guru!) but the concept should work. susan |
Replace character in string, not document
Thanks, that worked just fine. I have a brain cloud today & cound't
think of a way to do it. Thanks again. KS Susan wrote: if the format is always the same (six numbers, slash, letter) you could use Dim MyFileName as Variant Dim SelectedText as Variant SelectedText = 'wherever that cell/text is MyFileName = Left(SelectedText, 6) & "-" & Right(SelectedText, 1) ActiveDocument.SaveAs: MyFileName this is not tested & may contain errors (i'm no guru!) but the concept should work. susan |
Replace character in string, not document
one way
Sub test() Dim mystring As String, newstring As String mystring = "995451/U" newstring = Replace(mystring, "/", "-", 1) MsgBox newstring End Sub -- Gary "KS" wrote in message oups.com... Hello all. I have a macro in which I save the document creating the filename based on selected text in the document. However in some cases, the selected text looks like "995451/U." Obviously I cannot save using this name. I would like to convert this to "995451-U" for saving purposes only but NOT in the document. How can I do this? Thanks, KS |
All times are GMT +1. The time now is 04:40 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com