VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Excel Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 01-25-2008, 02:19 AM   #1
julesl

 
Joined: Jan 2008
Posts: 2
Kb Entries: 0
Articles: 0
Open, save and close Notepad file from Excel

Hi

I am trying to write some VBA code in Excel to Open a .dat file in Notepad, save the file and close Notepad. I've managed to open the notepad file using a filename stored in cell A1 (as the name changes daily) but I can't work out how to save the notepad file and close notepad.

Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _ (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpszClass As String, ByVal lpszTitle As String) As Long Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long Private Sub Form_Load2() Dim dTaskID As Double, path As String, file As String Dim hwndNotepad As Long Dim hwndTextbox As Long Dim MyName MyName = Range("A1") path = "C:\WINDOWS\notepad.exe" file = "J:\JUTEST\" & MyName dTaskID = Shell(path + " " + file, vbNormalFocus) hwndNotepad = FindWindowEx(0, 0, "Notepad", vbNullString) ???????????? - Code to save and close file Windows("BSconvert.xls").Activate Sheets("Files").Select Rows("1:1").Select Selection.Delete Shift:=xlToUp ActiveWorkbook.Save End Sub

Can anyone help me please?

Thanks in advance

Jules

Local Time: 08:38 PM
Local Date: 05-18-2013
Location:

 
Reply With Quote Top
Old 01-25-2008, 05:26 AM   #2
Norie

 
Joined: Jan 2005
Posts: 1,349
Kb Entries: 0
Articles: 0
Jules

What do you mean by a Notepad file?

There really isn't such a thing.

Notepad is just one of many applications that can be used to open text files.

And there are various VBA methods to work with those.

What is it you are actually trying to do?

Local Time: 02:38 AM
Local Date: 05-19-2013
Location:

 
Reply With Quote Top
Old 01-25-2008, 07:21 AM   #3
julesl

 
Joined: Jan 2008
Posts: 2
Kb Entries: 0
Articles: 0
Sorry I meant "I've managed to open the .dat file in Notepad using a filename stored in cell A1."

The file is padded out with a null hexadecimal value of "00" and the file needs to be padded out with spaces (hexadecimal value 20). The simplest solution I have found is to open the file in Notepad and Save it. I need to automate this process so that the end to end process of loading the file can be automated.


Hope this makes more sense


Thanks

Local Time: 08:38 PM
Local Date: 05-18-2013
Location:

 
Reply With Quote Top
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 06:38 PM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express