473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Spreadsheet - Prints Blank Pages And Unnecessary Underlines

7
Hellow everyone,
I am calling/manipulating Excel spreadsheet through VB 6.0. Most of my objectives are accomplished except some cosmetics.
Problem#1:
For example, after running my program to process a single record, when I proceed to print it, it prints the first page containing the processed record. It also prints 5 more blank pages without any record.

Problem#2:
Also, my intention is to print an Underline after writing each record, but the underlines are printed whether a record is written or not.

How can I get it to prints only the area that has data and draw an underline only when a record is processed and written?

Below is my entire module:


Expand|Select|Wrap|Line Numbers
  1.  
  2. ii = 5 
  3. w = 0 
  4. For Each R In xlWksht. Range("A5:N5"): w = w + R.ColumnWidth: Next 
  5.  
  6.     rht = xlWksht.Range("A5").RowHeight 
  7.  
  8.     Do Until M.qBW.EOF = True 
  9.         ii = ii + 2 
  10.         xlWksht.Cells(ii, 1).Value = M.qBW![Req No] 
  11.         xlWksht.Cells(ii, 2).Value = M.qBW![Description] 
  12.         xlWksht.Cells(ii, 3).Value = "" 
  13.         xlWksht.Cells(ii, 4).Value = M.qBW![ClientName] & Chr(10) & M.qBW![Status] 
  14.         xlWksht.Cells(ii, 5).Value = M.qBW![P L] & Chr(10) & M.qBW![TotalProg1Hrs] 
  15.  
  16.         SrchCriteria = "[Name]= " & "'" & M.qBW![Personnel2] & "'" 
  17.         rsinPers.FindFirst SrchCriteria 
  18.         If rsinPers.NoMatch = False Then 
  19.             xlWksht.Cells(ii, 6).Value = rsinPers![Initials] & Chr(10) & M.qBW![TotalProg2Hrs] 
  20.         End If 
  21.  
  22.         SrchCriteria = "[Name]= '" & M.qBW![Personnel3] & "'" 
  23.         rsinPers.FindFirst SrchCriteria 
  24.         If rsinPers.NoMatch = False Then 
  25.             xlWksht.Cells(ii, 7).Value = rsinPers![Initials] & Chr(10) & M.qBW![TotalProg3Hrs] 
  26.         End If 
  27.  
  28.         SrchCriteria = "[Name]= '" & M.qBW![Personnel4] & "'" 
  29.         rsinPers.FindFirst SrchCriteria 
  30.         If rsinPers.NoMatch = False Then 
  31.             xlWksht.Cells(ii, 8).Value = rsinPers![Initials] & Chr(10) & M.qBW![TotalProg4Hrs] 
  32.         End If 
  33.  
  34.         SrchCriteria = "[Name]= '" & M.qBW![Personnel5] & "'" 
  35.         rsinPers.FindFirst SrchCriteria 
  36.         If rsinPers.NoMatch = False Then 
  37.             xlWksht.Cells(ii, 9).Value = rsinPers![Initials] & Chr(10) & M.qBW![TotalProg5Hrs] 
  38.         End If 
  39.  
  40.         SrchCriteria = "[Name]= '" & M.qBW![Personnel6] & "'" 
  41.         rsinPers.FindFirst SrchCriteria 
  42.         If rsinPers.NoMatch = False Then 
  43.             xlWksht.Cells(ii, 10).Value = rsinPers![Initials] & Chr(10) & M.qBW![TotalProg6Hrs] 
  44.         End If 
  45.  
  46.         xlWksht.Cells(ii, 11).Value = "-" & Chr(10) & M.qBW.Fields("Per Hrs") 
  47.         xlWksht.Cells(ii, 12).Value = M.qBW.Fields("EstimatedTotalHours") & Chr(10) & M.qBW.Fields("Tot Hrs") 
  48.         xlWksht.Cells(ii, 13).Value = M.qBW![Start  Date] & Chr(10) & M.qBW![Start Date] 
  49.         xlWksht.Cells(ii, 14).Value = M.qBW![End Date] & Chr(10) & M.qBW![End  Date] 
  50.  
  51.         If M.qBW![Comments] = "" Or IsNull(M.qBW![Comments]) Then 
  52.             mystr = "Comments:" & Chr(10) & "NO COMMENTS FOR THIS RECORD!" 
  53.         Else 
  54.             mystr = "Comments:" & "'" & xlApp.Clean(Trim(M.qBW![Comments])) 
  55.         End If 
  56.  
  57.         Do 
  58.             Pos = InStr(Pos + 1, mystr, ":") 
  59.             If Not Pos = 0 Then 
  60.                 If Mid(mystr, Pos - 5, 1) = "/" Then 
  61.                     mystr = Left(mystr, Pos - 11) & Chr(10) & Mid(mystr, Pos - 10, 10) & Chr(10) & Mid(mystr, Pos + 1) 
  62.                     Pos = Pos + 2 
  63.                 End If 
  64.             End If 
  65.          Loop While Not Pos = 0 
  66.  
  67.  
  68.         xlWksht.Cells(ii + 1, 1).Value = "Comments:" 
  69.         xlWksht.Cells(ii + 1, 2).Value = Mid(mystr, 11) 
  70.  
  71.         With xlWksht.Range(xlWksht.Cells(ii + 1, 2), xlWksht.Cells(ii + 1, 14)) 
  72.             .HorizontalAlignment = xlLeft 
  73.             .VerticalAlignment = xlTop 
  74.             .WrapText = True 
  75.             .Orientation = 0 
  76.             .MergeCells = True 
  77.             .RowHeight = .Font.Size * (Len(xlWksht.Range("A" & ii + 2).text) - Len("Comments:")) / w + rht + (rht - .Font.Size) ' + newlinecnt * .Font.Size
  78.         End With 
  79.  
  80.         xlWksht.Columns("A:A").ColumnWidth = 9.15 
  81.  
  82.          'Draw Underline after each record:
  83.          '---------------------------------
  84.         TStr = "A" & CStr(ii + 1) & ":N" & CStr(ii + 1) 
  85.         xlWksht.Range(TStr).Select 
  86.         If Not IsEmpty(Selection.Range("A1")) Then 'check if first cell is empty
  87.             With xlWksht.Range(TStr).Borders(xlEdgeBottom) 
  88.                 .LineStyle = xlDouble 
  89.                 .Weight = xlThin 
  90.                 .ColorIndex = xlAutomatic 
  91.             End With 
  92.         End If 
  93.         M.qBW.MoveNext 
  94.     Loop 
  95.  
  96.     xlWksht.PageSetup.LeftFooter = " Legend:" & Chr(10) & "See Estimated Actual Tot.Hrs. Column: Top Number = Estimated Hrs. and Bottom Number = Actual Hrs." & Chr(10) & "See Estimated Actual Start/End Dates Columns: Top dates = Estimated Start/End dates and Bottom dates = Actual Start/End dates" 
  97.  
  98.  
  99.     strAnswer =  MsgBox("Would you like to Print this spreadsheet?", vbYesNo, "Print Option") 
  100.  
  101.     If strAnswer = vbYes Then 
  102.         Goto PrintSpreadsheet 
  103.     Else 
  104.         Goto ViewSpreadsheet 
  105.     End If 
  106.  
  107. PrintSpreadsheet: 
  108.      'Set up Print area:
  109.      '-----------------
  110.     xlWksht.PageSetup.PrintArea = xlWksht.Range("A1:" & xlWksht.Cells.SpecialCells(xlCellTypeLastCell).Address) 
  111.  
  112.     xlApp.ActiveWorkbook.Save 
  113.  
  114.     xlApp.Visible = True 
  115.     xlApp.UserControl = True 
  116.  
  117.     Goto CloseAllObjects 
  118.  
Thanks.
GiftX.
Sep 26 '07 #1
0 1177

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: B-Dog | last post by:
I'm using the code from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/printwinforms.asp to print some info from a database and I've struggled through customizing...
4
by: Andreas Bauer | last post by:
Hi, I have to audit some c# code. I know in the options I can adjust how the code should be formatted while entering it. But is there any way to apply afterwards a code template to the classes...
1
by: =?Utf-8?B?Q3ludGlh?= | last post by:
I'VE ALREADY CHANGED INK CARTRIDGES, UNINSTALLED AND REINSTALLED THE PRINTER, RESTARTED MY COMPUTER ETC... AND STILL PAGES COME OUT BLANK... THIS PRINTER WAS WORKING FINE JUST BEFORE!! CAN...
2
TMS
by: TMS | last post by:
The spreadsheet is due today and i needed help with the last two parts of the spreadsheet, so I went to my teacher. My spreedsheet was working BETTER before he made me change it. Now it prints a...
0
by: mix01 | last post by:
Hi, I am trying to get some VBA code working, but am preplex as to why it does not work. I would really appreciate any level of help. Many thanks, Mix01 Version of the program
3
by: D.Stone | last post by:
I'm trying to import an Excel spreadsheet into an existing Access table using Office 2003. Ultimately, the plan is to do it programmatically using TransferSpreadsheet, but to check that the file...
8
by: SMERSH009 | last post by:
Hi All. Let's say I have some badly formatted text called doc: doc= """ friendid Female 23 years old
3
by: GiftX | last post by:
Good morning members. I am using VB6 to generate a spreadsheet. My module is working okay but one of my objectives is to print an underline after writing each record in the spreadsheet, just to show...
8
by: Perl Beginner | last post by:
I am using Win32. I have created an excel spreadsheet, formatted the columns and rows, and would like to write to the cells…all of this using Spreadsheet::WriteExcel. My issue is, my script is very...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.