VBA Open notepad file and copy it's contents then paste to word
Posted on 2006-04-06
I need to open a text file in notepad, copy it's contents and then paste them into a word document.
I can open the text pad file fine using Shell "notepad c\:Test.txt" but do not know how I can then copy it's content. I know that this is strictly outside the capabilities of vba but wondered if anyone has ever done this.
I have tried using the code below to write the text in as stream, but as it contains various charactor sets eg Kanji and English it screws up the charactors due to the local settings etc, the only way I can get an exact copy in is when I manually open the text file and copy, paste it in.
Dim fso As FileSystemObject
Dim sFilename As String
Dim tsmfile As TextStream
Dim strXML As String
Dim TempFileLoc As String
Dim strXMLComp As String
Dim strXMLCompOne As String
Dim TempFileLocText As String
TempFileLocText = gobjDASLoc.TempPath("Test.txt")
sFilename = TempFileLoc
Set fso = New FileSystemObject
Set tsmfile = fso.OpenTextFile(sFilename, ForReading, False)
If tsmfile Is Nothing Then
strXML = tsmfile.ReadAll
ActiveDocument.Bookmarks.Add("bmk_xxx").Range.Text = strXML