Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
Trying to do something simple (or so I thought) but not working and possibly going to send me over the edge....
I'm trying to write a line out to a text file but both looking at the example in the API Guide and in the few forum posts here I still can't get anything to output.
Here's what I'm doing:
sub CreateTextOutput
set v = ActiveDocument.Variables("vFullPath")
vLocalPath = v.GetContent.String
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(vLocalPath, true)
'Export Header Line and spacing line
set FileStream = objFile.OpenAsTextStream(8)
FileStream.WriteLine vLocalPath
FileStream.WriteBlankLines 1
FileStream.Close
objFile.Close
end sub
where vFullPath is set to a file location on my local hard drive.
The result is that I get the file created in the location but with nothing in the file itself.
Anyone see what I'm doing wrong?
Chris
Not quite sure I understand what you are trying to do but the following macro will simply create and write to a text file.
You can set the vFullPath variable in the Document QV script or from Document > Settimgs > Vaiable Overview.
Npte the vFullPath needs the directory and file name. e.g. c:\temp\myfile.txt
sub CreateTextOutput
set v = ActiveDocument.Variables("vFullPath")
vLocalPath = v.GetContent.String
set objFSO = CreateObject("Scripting.FileSystemObject")
set FileStream = objFSO.OpenTextFile(vLocalPath, 2, true) 'Change 2 to 8 for append
FileStream.WriteLine("xxxx")
FileStream.Close()
end sub
Haven't used vbscript in awhile but do you need to specify an append mode? Would the last WriteBlankLines be overwriting the vLocalPath line already added. Just a guess.
FileStream.WriteLine vLocalPath
FileStream.WriteBlankLines 1
Hi both,
Yes Tom, you are correct in so far as I'm just trying to write a line out to a text file. In the end I'm trying to create a text file with a header row, a blank line and then the contents of a straight table. The file is for importing into a seperate system (Hyperion).
I ended up getting somewhere this morning by not using the File Stream object at all and just doing a file.writeline.
Jeremy, you are correct in what you are saying too in that I will write a line out to a file and then use an append function to add chart data to it. I tried to use chart.AppendExport but ended up getting html out instead of the data itself which was a bit confusing; especially since I used the chart.Export function previously to test out the result and got all of the data out as I wanted it.
Going to keep plugging away at it, using macros is proving to be a bit of a nightmare though.
Thanks,
Chris