Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 11-20-2018, 01:56 PM
macropod's Avatar
macropod macropod is offline Save as txt : How to detect if Unicode encoding is required? Windows 7 64bit Save as txt : How to detect if Unicode encoding is required? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

VBorNotVB: When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had. See your edited post.

Looping through every character in a document is slow and unnecessary - excruciatingly so when every character is unnecessarily selected. In any event, testing whether characters fall in ASCII range 0-127 says nothing about whether they're Unicode; they might also be characters that fall in ASCII range 128-255!

Instead, try something based on:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument
  With .Range.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "[^1-^255]"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
  i = Len(.Range.Text) - .InlineShapes.Count
  .Undo
End With
If i > 1 Then
  MsgBox "Document contains Unicode characters."
Else
  MsgBox "Document contains only ASCII characters."
End If
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Tags
activedocument.saveas, encoding, txt



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro help - converting proprietary encoding to unicode, keep formatting kmawhood Word VBA 3 04-29-2016 04:06 PM
Save as txt : How to detect if Unicode encoding is required? Does 'Save as Unicode text' equal UTF-8 Chayes Excel 1 07-20-2012 03:07 AM
Save as txt : How to detect if Unicode encoding is required? Custom Dictionary & Unicode encoding? markus staubmann Word 3 03-28-2012 05:23 AM
Save as txt : How to detect if Unicode encoding is required? Save Word doc in unicode html (utf-8) rybrns Word 5 09-26-2011 02:18 PM
Save as txt : How to detect if Unicode encoding is required? Unicode Encoding Type Rose44 Excel 2 08-09-2009 09:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft