Using VBA to write to Notepad

  reddwarfcrew 20:13 04 Apr 2007

Hi, I have some VBA code in Access that writes to Word, but I'd prefer to write to notepad if possible as the code slows right down when it opens Word.

Has anyone got any suggestions? My code is:

Set objWord = CreateObject("word.application")
Set objWord = GetObject(, "word.application")
objWord.Visible = True
objWord.Selection.TypeText Text:=searchDB
objWord.ChangeFileOpenDirectory "J:\PCS\"
objWord.ActiveDocument.SaveAs fileName:="searchDB.js", FileFormat:=wdFormatText
objWord.ActiveDocument.Close wdSaveChanges = False

  VoG II 20:20 04 Apr 2007

This is how to do write to a .TXT file in Excel VBA - Access should be similar:

Sub MyOutput()
Dim iMyFreeFile As Integer
Dim string1 As String
Dim var1
string1 = "hello"
var1 = 3

' get a free file number
iMyFreeFile = FreeFile

' open the text file - please note this replaces the file
Open "c:\xltext.txt" For Output As #iMyFreeFile

' write whatever you want

Write #iMyFreeFile, string1, var1
' as long as you write on one line, the data is comma delimited

' if you add another write statement, the data will be on the next line
Write #iMyFreeFile, string1, var1

' now close the file
Close #iMyFreeFile
End Sub

  reddwarfcrew 20:29 04 Apr 2007

thats a great help.

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Galaxy Note 8 vs iPhone X

This is what design agencies will look like in 2032

How to update iOS on iPhone or iPad

WhatsApp : comment lire vos messages sans que l’expéditeur le sache