473,671 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Spreadsheet - Prints Blank Pages And Unnecessary Underlines

7 New Member
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 1184

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

Similar topics

0
1130
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 the report to fit what I need and thought I had it all working great since my print preview looked great but when I hit the print button I get blank pages at the printer. I've tried two different printers with the same results. Any ideas?
4
2869
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 to adjust their appearance (except ctrl-k ctrl-f)? Foremost how to clear unnecessary blank lines, e.g reduce 4 blank lines to one. I don´t want to change every class manually. Thanks in advance for any hint.
1
1147
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 SOMEBODY HELP?? THANKS! -- Cyntia
2
1787
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 widget address in one of the cells for no apparant reason (I can't locate why the event is doing that), and it doesn't evaluate. He wants me to use 2 dictionaries: One that holds the cell number and expression, and Two that holds the result of...
0
5088
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
5323
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 has no problems, I've done it manually with the Import Spreadsheet wizard. The worksheet has 43 rows, and I import a named range defined as "=Sheet1!$C:$E". The import works, but I get a table with 64K rows, all but 43 being blank!
8
1262
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
1561
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 where one record ends and the next begins. However, even if I process only one record and try to print it, it prints several blank pages including underlines, even if there are no records. How can I instruct it to strictly print an underline...
8
9409
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 vast with a lot of subroutines, but I need the excel spreadsheet created in the main subroutine becasue this is where the data is that i want to capture. So if I create and format the spreadsheet within the main subroutine, and as it loops through,...
0
8481
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8400
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8602
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7441
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4412
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.