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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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.
 
Upvote 0
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".
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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
Back
Top