LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Help with Slow Print Routine

Hi!

I have to save a worksheet in tab-delimited text format, and I cannot retain
the quotation mark text delimiters that are added to cell values that contain
commas. After searching around for ideas on how to eliminate the quotation
marks, I found a technique whereby I essentially print to a file directly,
rather than simply saving the sheet in tab-delimited text format. But my
solution runs extremely slowly, taking about 20 minutes to save a sheet 150
columns by 2500 rows. Here's my code - can anyone tell me how to make it run
faster, like about 20 times faster?


Dim TextLine As String
Dim i, j, FileNo As Integer
Dim OutFileName, TextLine As String
Dim sh As Worksheet
Dim fd As FileDialog
Dim f, fs, s, ts As Variant
Dim wb As Workbook

'Prompt the user for a folder to put the text files

Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.InitialFileName = "C:\Temp\"
.InitialView = msoFileDialogViewDetails
If .Show = -1 Then

For Each sh In ActiveWorkbook.Worksheets
If Mid(sh.Name, 1, 18) = "MatMasterLoadSheet" Then
FileNo = FreeFile
OutFileName = fd.InitialFileName & sh.Name & ".txt"
Open OutFileName For Output Access Write As #FileNo
For i = 1 To sh.UsedRange.Rows.Count
'Reset the text line at new row
TextLine = ""
For j = 1 To sh.UsedRange.Columns.Count
If j = sh.UsedRange.Columns.Count Then
'Add the last cell to the textline, no tab, and print the line
TextLine = TextLine & sh.Cells(i, j)
Print #FileNo, TextLine
Else
'Append column content to textline, with a tab
TextLine = TextLine & sh.Cells(i, j) & vbTab
End If
Next j
Next i
Close #FileNo
End If
Next sh
Else
MsgBox "Worksheets NOT Saved!!" & vbCrLf & "Please drive through!!!"
End If
End With


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB routine to print to PDF? fedude Excel Worksheet Functions 4 March 15th 08 02:04 AM
Print Routine Error Nancy X[_2_] Excel Programming 4 July 9th 07 06:06 PM
Testing for Slow Routine ExcelMonkey Excel Programming 3 February 1st 06 04:15 PM
Routine running slow (memory leak?) ExcelMonkey Excel Programming 3 February 1st 06 11:20 AM
Slow FileSearch Routine stratuser Excel Programming 0 May 14th 04 02:56 PM


All times are GMT +1. The time now is 06:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"