Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default CreateObject("Notepad") ?


As part of my code, I want to change the encoding of some .txt files from
Unicode to ANSI. Is there a direct way to do this in VBA.

If not, I want add code to create a Notepad session and then use the
SendKeys method to do this. How do I create a Notepad session in VBA.

I know I can start a program called Monarch through VBA using:

Set MonObj = CreateObject("Monarch32")

What's the equivalent for Notepad?

Thanks in advance,

Alan

--
achidsey
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default CreateObject("Notepad") ?

I am not sure that Notepad supports automation. But a better way to do what
you want would be to directly open a text file and use the Input# and Print#
statements to read and write directly to the file. By bypassing notepad you
avoid some of the possible problems using SendKeys, as when some system event
(or user event) interferes with the keystrokes and starts typing your
Sendkeys statements somewhere where they aren't supposed to go.

Basic structure would be as follows:

Dim InputFile as String, OutputFile as String, TextChar as String
InputFile = "C:\TEST.txt" ' replace with actual path to input file
OutputFile = "C:\TEST OUTPUT.txt" ' replace with output path
Open InputFile For Input As #1 ' Open file.
Open OutputFile for Output as #2 ' Open the output file: will either create
it or overwrite existing file
Do While Not EOF(1) ' Loop until end of file.
TextChar = Input(1, #1) ' Get one character.
' Perform any desired conversion here
Print #2, TextChar; ' Wirte to output file
Loop
Close #1 ' Close files
Close #2


--
- K Dales


"achidsey" wrote:


As part of my code, I want to change the encoding of some .txt files from
Unicode to ANSI. Is there a direct way to do this in VBA.

If not, I want add code to create a Notepad session and then use the
SendKeys method to do this. How do I create a Notepad session in VBA.

I know I can start a program called Monarch through VBA using:

Set MonObj = CreateObject("Monarch32")

What's the equivalent for Notepad?

Thanks in advance,

Alan

--
achidsey

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default CreateObject("Notepad") ?

K Dales

Thanks for the information.

Alan
--
achidsey


"K Dales" wrote:

I am not sure that Notepad supports automation. But a better way to do what
you want would be to directly open a text file and use the Input# and Print#
statements to read and write directly to the file. By bypassing notepad you
avoid some of the possible problems using SendKeys, as when some system event
(or user event) interferes with the keystrokes and starts typing your
Sendkeys statements somewhere where they aren't supposed to go.

Basic structure would be as follows:

Dim InputFile as String, OutputFile as String, TextChar as String
InputFile = "C:\TEST.txt" ' replace with actual path to input file
OutputFile = "C:\TEST OUTPUT.txt" ' replace with output path
Open InputFile For Input As #1 ' Open file.
Open OutputFile for Output as #2 ' Open the output file: will either create
it or overwrite existing file
Do While Not EOF(1) ' Loop until end of file.
TextChar = Input(1, #1) ' Get one character.
' Perform any desired conversion here
Print #2, TextChar; ' Wirte to output file
Loop
Close #1 ' Close files
Close #2


--
- K Dales


"achidsey" wrote:


As part of my code, I want to change the encoding of some .txt files from
Unicode to ANSI. Is there a direct way to do this in VBA.

If not, I want add code to create a Notepad session and then use the
SendKeys method to do this. How do I create a Notepad session in VBA.

I know I can start a program called Monarch through VBA using:

Set MonObj = CreateObject("Monarch32")

What's the equivalent for Notepad?

Thanks in advance,

Alan

--
achidsey

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
CreateObject("Excel.Application") Olivia Towery Excel Worksheet Functions 4 June 12th 06 12:07 AM
Set OutApp = CreateObject("Outlook.Application") - Runtime error 429 Buffyslay Excel Programming 2 July 20th 05 05:06 PM
ASP: CreateObject("Excel.Application") IIS 6.0 Win2003 Mau[_2_] Excel Programming 0 July 20th 05 11:45 AM
Excel:Runtime Error 7 "Not enough Memory" with CreateObject (SAP.B sebastienm Excel Programming 0 July 24th 04 08:35 AM
CreateObject("Excel.Application") - Access denied Luca[_2_] Excel Programming 0 February 6th 04 01:21 PM


All times are GMT +1. The time now is 12:27 PM.

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"