VBA: How can I write to the next column in a test.wks file?

Alex00001

New Member
Joined
Sep 5, 2006
Messages
8
Hi,

I am not an experienced user and I have a problem writing output from a simulation model to a .wks format file. I get VBA to make the file and write data in it. Until now I have made the following code, but it only writes data to the first column. Can anybody tell me how to write data to the second and third etc columns?
Writing to an excel file is not possible because of file corruption caused by the simulation software.

Below the code I have tried sofar. But everything I write ends op cramped in first column.

Thanks a lot for your help!

Code:
  Open "test.wks" For Output As #1
    
        Write #1, OutputFileName
        Write #1, 'Write blank line.
        Write #1, 'Write blank line.
        Write #1, 1, 2
        Write #1, 1; Tab(10); 2
        Print #1, "This is a test"  ' Print text to file.
        Print #1,   ' Print blank line to file.
        Print #1, "Zone 1"; Tab; "Zone 2"   ' Print in two print zones.
        Print #1, "Hello"; " "; "World"     ' Separate strings with space.
        Print #1, Spc(5); "5 leading spaces "   ' Print five leading spaces.
        Print #1, Tab(10); "Hello"  ' Print word at column 10.
        
close #1
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,547
It looks like you are writing a text file not a "wks" file. Just making the file extension ".wks" in your filename doesn't mean you are writing into "wks" format. Set up your layout in an empty new worksheet and then save that as filetype WKS.
 

Alex00001

New Member
Joined
Sep 5, 2006
Messages
8
Could you give me some pointers on how to set the file up in wks format?
I'd be gratefull
 

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,547
As I said, put the data in a worksheet and ... "save that as filetype WKS". When you do File/Save As ... change the Filetype in the "Save As Type" dropdown to "WKS".
 

Forum statistics

Threads
1,141,096
Messages
5,704,312
Members
421,338
Latest member
Pepess

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top