Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2007

Tip: Looking for answers? Try searching our database.

MACRO to convert to hex

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
UnicodeConfusion - 01 Feb 2007 22:04 GMT
I need to convert ascii characters (including unicode) to 4 digit hexadecimal
representation.  The alt+x  (Selection.ToggleCharacterCode) functionality
works for a single character, but I am trying to write a macro to convert
every character in the file. I can't figure out how to parse through the
document...

any suggestions?

Stephanie
Helmut Weber - 02 Feb 2007 01:43 GMT
Hi Stephanie,

how about this one:

Sub Test2()
Dim rngChr As Range
Dim strTmp As String
For Each rngChr In ActiveDocument.Characters
  strTmp = CStr(Hex(AscW(rngChr)))
  ' cause I could't get to work it with format
  While Len(strTmp) < 4
     strTmp = "0" & strTmp
  Wend
  MsgBox strTmp ' or your code
Next
End Sub

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

John Nurick - 02 Feb 2007 06:49 GMT
Hi Helmut

This might be faster:

...
Dim strTmp As String * 4
...
  strTemp = Right("000" & Hex(AscW(rngChr)),4)
  MsgBox ...

>Hi Stephanie,
>
[quoted text clipped - 12 lines]
>Next
>End Sub

--
John Nurick [Microsoft Access MVP]

Please respond in the newsgroup and not by email.
Helmut Weber - 02 Feb 2007 12:32 GMT
Hi John,

>This might be faster:
>
[quoted text clipped - 3 lines]
>   strTemp = Right("000" & Hex(AscW(rngChr)),4)
>   MsgBox ...

At least it looks better, and faster, too. :-)

But in fact, it isn't. :-(

For 70,000 characters, I get differences of some hundredths seconds.
Sometimes in favor of solution, sometimes in favor of mine.

Have a nice day.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

John Nurick - 02 Feb 2007 19:53 GMT
>>   strTemp = Right("000" & Hex(AscW(rngChr)),4)

>At least it looks better, and faster, too. :-)
>
>But in fact, it isn't. :-(
>
>For 70,000 characters, I get differences of some hundredths seconds.
>Sometimes in favor of solution, sometimes in favor of mine.

Thanks for the feedback, Helmut.

--
John Nurick [Microsoft Access MVP]

Please respond in the newsgroup and not by email.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.