Problem reading text from range using offset and printing to text file

simeon

New Member
Joined
Apr 29, 2011
Messages
2
Hi,

I am problems writing a VB script in Excel 2003 to read through the individual cells in an range, extract the text using offset and write the same text to another textfile (this is a precursor to wrting a macro to reformat the text for another application).

What I have is spreadsheet that contained a named range called "TestMethods" and is 14 rows by 8 columns. I can successufully count the number of rows to create a For ... Next loop to go through the 14 rows, but currently it's just writing blanks.

this is what the code looks like:

Sub OpenTxtfile()
Dim oFile As Integer, NoofMethods As Integer, Rw As Integer
Dim ObjDefnTable

Set ObjDefnTable = Worksheets("Mapping").Range("TestMethods")

oFile = FreeFile()
Open "C:\Backup\ShopITv60.sdt" For Output As oFile

Windows("SDT_Gen_Example.xlsm").Activate

' Determine no of rows to read through (incl hdr row for now)
NoofMethods = ObjDefnTable.Rows.Count

For Rw = 2 To NoofMethods Step 1
Print #oFile, "Test Method Row " & Rw & ObjDefnTable.Offset(Rw, 2).Text
Next Rw

Close #oFile

End Sub
Any advice will be much appreciated.

Thanks,

Simeon
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
For those of you who are interested I realised that I was using the wrong object type to extract the cell value :(

I needed to use the "Cells" object. Therefore the print statement should look like:

Print #oFile, "Test Method Row " & Rw & Worksheets("Mapping").Range("TestMethods").Cells(Rw, 1).Text
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

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