Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel-Match 1st text character in a string to a known character? bushlite Excel Worksheet Functions 2 January 15th 07 06:36 PM
How do I replace last numeric string from a alphanumeric string? Christy Excel Discussion (Misc queries) 3 August 11th 06 12:17 AM
Function to return Character Position of Xth character within a string Andibevan[_2_] Excel Programming 4 June 9th 05 03:24 PM
How do I replace * as a character in a string in Excel? nicolegt Excel Programming 1 January 21st 05 10:42 AM
How to replace this character ... Harish Mohanbabu Excel Programming 2 February 18th 04 04:20 PM


All times are GMT +1. The time now is 01:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"