473,797 Members | 3,204 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access Excel Automation Formatting Problem

Hi there
Have a database, where front-end interface allows user to select a ms
access database. From there, standard tables are linked. Routine,
that creates a spreadsheet, for each table a separate sheet within
spreadsheet is created. Particular fields are selected.

User requires fields to be auto-fitted. Problem, is that some tables
have more than 1200> rows. Code generates error message. Is there a
way of getting around this problem. See ***

Code -->

Public Function Export_Excel_10 (dblocation As Variant)
On Error GoTo Err_Export_Exce l_10

'***AIM-Testing
'CALL Export_Excel_10 ("T:\TechCentra l\techCENTRAL\S tdSpecs\WWL\A00 00.MDB")

Dim x1 As Excel.Applicati on
Dim excelwbkXL As Object
Dim excelwksXL As Object
Dim counter As Integer, row As Integer
Dim strSQL1 As String, strSQL4 As String
Dim strSQL4A As String, strSQL4B As String, strSQL4C As String,
strSQL4D As String
Dim strSQL4E As String, strSQL4F As String, strSQL4G As String,
strSQL4H As String
Dim strPath_Securit y_WkGrp As String, strPath_Securit y_User As String
Dim strPath_Securit y_Pwd As String, strPath As String
Dim cnt As New ADODB.Connectio n, rst As New ADODB.Recordset
Dim D As DAO.Database, R As DAO.Recordset, s As String
Dim I As Integer
Dim strTable As Integer
Dim posLONG_DESCR As Integer, posMAIN_SIZE As Integer, posRUN_SIZE As
Integer, posBRAN_SIZE As Integer
Dim posSCHEDULE As Integer, posRATING As Integer, posSHORT_DESC As
Integer, posCATALOG As Integer

'***AIM-Column Position of fields
posLONG_DESCR = 1
posMAIN_SIZE = 2
posRUN_SIZE = 3
posBRAN_SIZE = 4
posSCHEDULE = 5
posRATING = 6
posSHORT_DESC = 7
posCATALOG = 8

'***AIM-Default Settings
dblocation = "C:\WWL.PipeSpe c\book1.xls"
strPath = "C:\WWL.PipeSpe c\PipeSpec.mdb"
strPath_Securit y_WkGrp = "C:\WWL.PipeSpe c\WorkGroup\wwl _sys1.mda"
strPath_Securit y_User = ""
strPath_Securit y_Pwd = ""
strTable = 0

'***AIM-Open the Excel spreadsheet.
Set x1 = CreateObject("E xcel.applicatio n")
Set excelwbkXL = x1.Workbooks.Op en(dblocation)

'***AIM-Display Excel and give user control of Excel
x1.Visible = True
x1.UserControl = True

'***AIM-Set the string to the path of the Working database
Set cnt = New ADODB.Connectio n
With cnt
.Provider = "Microsoft.Jet. OLEDB.4.0"
.CursorLocation = adUseClient
'.Properties("J et OLEDB:Database Password") = "" --> password
.Properties("Je t OLEDB:System Database") =
strPath_Securit y_WkGrp
.Open strPath, strPath_Securit y_User, strPath_Securit y_Pwd
End With

s = "SELECT Table_Name FROM STANDARD_TABLES "
Set D = CurrentDb
Set R = D.OpenRecordset (s)
'***AIM-LOOP THROUGH RECORDS IN PathTextTech
Do Until R.EOF

If R!table_name = "Pass" Or R!table_name = "Timeout" Then
'do nothing
ElseIf R!table_name <> "pumpa" Then
strSQL4A = "SELECT [LONG_DESCR], [MAIN_SIZE], [RUN_SIZE],
[BRAN_SIZE], [SCHEDULE], [RATING], [SHORT_DESC], [CATALOG] from " &
R!table_name
strSQL4 = strSQL4A & " ORDER BY [LONG_DESCR], [MAIN_SIZE],
[RUN_SIZE], [BRAN_SIZE], [SCHEDULE], [RATING], [SHORT_DESC], [CATALOG]
" & ";"

ElseIf R!table_name = "pumpa" Then
strSQL4A = "SELECT [LONG_DESCR], [LONG_DESCR], [CATALOG]
from " & R!table_name
strSQL4 = strSQL4A & " ORDER BY [LONG_DESCR], [CATALOG] "
& ";"
End If

strTable = strTable + 1

Set rst = New ADODB.Recordset
rst.Open strSQL4, cnt

'***AIM-Add new sheet
Set excelwksXL = excelwbkXL.Work sheets.Add

'***AIM-Spreadsheet - sheet name
excelwksXL.NAME = R!table_name

If R!table_name <> "pumpa" Then

'***AIM-Make the column headers.
For I = 1 To rst.Fields.Coun t - 1

'***AIM-Fields
If rst.Fields(I).N AME = "LONG_DESCR " Then
excelwksXL.Cell s(1, posLONG_DESCR). Value =
rst.Fields(I).N AME
ElseIf rst.Fields(I).N AME = "MAIN_SIZE" Then
excelwksXL.Cell s(1, posMAIN_SIZE).V alue =
rst.Fields(I).N AME
ElseIf rst.Fields(I).N AME = "RUN_SIZE" Then
excelwksXL.Cell s(1, posRUN_SIZE).Va lue =
rst.Fields(I).N AME
ElseIf rst.Fields(I).N AME = "BRAN_SIZE" Then
excelwksXL.Cell s(1, posBRAN_SIZE).V alue =
rst.Fields(I).N AME
ElseIf rst.Fields(I).N AME = "SCHEDULE" Then
excelwksXL.Cell s(1, posSCHEDULE).Va lue =
rst.Fields(I).N AME
ElseIf rst.Fields(I).N AME = "RATING" Then
excelwksXL.Cell s(1, posRATING).Valu e =
rst.Fields(I).N AME
ElseIf rst.Fields(I).N AME = "SHORT_DESC " Then
excelwksXL.Cell s(1, posSHORT_DESC). Value =
rst.Fields(I).N AME
ElseIf rst.Fields(I).N AME = "CATALOG" Then
excelwksXL.Cell s(1, posCATALOG).Val ue =
rst.Fields(I).N AME
End If

Next I

'***AIM-Get data from the database and insert
'***AIM-it into the spreadsheet.
row = 2
Do While Not rst.EOF
For I = 1 To rst.Fields.Coun t - 1
'***AIM-Fields
If rst.Fields(I).N AME = "LONG_DESCR " Then
excelwksXL.Cell s(row, posLONG_DESCR) =
rst.Fields(I).V alue
ElseIf rst.Fields(I).N AME = "MAIN_SIZE" Then
excelwksXL.Cell s(row, posMAIN_SIZE) =
rst.Fields(I).V alue
ElseIf rst.Fields(I).N AME = "RUN_SIZE" Then
excelwksXL.Cell s(row, posRUN_SIZE) =
rst.Fields(I).V alue
ElseIf rst.Fields(I).N AME = "BRAN_SIZE" Then
excelwksXL.Cell s(row, posBRAN_SIZE) =
rst.Fields(I).V alue
ElseIf rst.Fields(I).N AME = "SCHEDULE" Then
excelwksXL.Cell s(row, posSCHEDULE) =
rst.Fields(I).V alue
ElseIf rst.Fields(I).N AME = "RATING" Then
excelwksXL.Cell s(row, posRATING) =
rst.Fields(I).V alue
ElseIf rst.Fields(I).N AME = "SHORT_DESC " Then
excelwksXL.Cell s(row, posSHORT_DESC) =
rst.Fields(I).V alue
ElseIf rst.Fields(I).N AME = "CATALOG" Then
excelwksXL.Cell s(row, posCATALOG) =
rst.Fields(I).V alue
End If

Next I
row = row + 1
rst.MoveNext
Loop

ElseIf R!table_name = "pumpa" Then

'***AIM-Make the column headers.
For I = 1 To rst.Fields.Coun t - 1

'***AIM-Fields
If rst.Fields(I).N AME = "LONG_DESCR " Then
excelwksXL.Cell s(1, 2).Value = rst.Fields(I).N AME
ElseIf rst.Fields(I).N AME = "CATALOG" Then
excelwksXL.Cell s(1, 3).Value = rst.Fields(I).N AME
End If

Next I

'***AIM-Get data from the database and insert
'***AIM-it into the spreadsheet.
row = 2
Do While Not rst.EOF
For I = 1 To rst.Fields.Coun t - 1
'***AIM-Fields
If rst.Fields(I).N AME = "LONG_DESCR " Then
excelwksXL.Cell s(row, 2) = rst.Fields(I).V alue
ElseIf rst.Fields(I).N AME = "CATALOG" Then
excelwksXL.Cell s(row, 3) = rst.Fields(I).V alue
End If

Next I
row = row + 1
rst.MoveNext
Loop

End If
*************** *************** *************** *************** *******
'***AIM-Need to disable, can't handle large number of rows
(2000>)
'***AIM-Formatting
'excelwksXL.ran ge(excelwksXL.C ells(1, 1), _
'excelwksXL.Cel ls(1, row)).Select
'x1.Selection.E ntireColumn.Aut oFit
'x1.Selection.C olumns.AutoFit
'excelwksXL.ran ge(excelwksXL.C ells(1, 1), excelwksXL.Cell s(2,
row)).Select
'excelwksXL.ran ge(excelwksXL.C ells(1, 1), excelwksXL.Cell s(8,
200)).Select
'x1.Selection.E ntireColumn.Aut oFit
'***AIM-Print Setup properties
'x1.ActiveSheet .PageSetup.Zoom = 70
'x1.ActiveSheet .PageSetup.Orie ntation = xlLandscape
'x1.ActiveSheet .PageSetup.Prin tArea = "$A$1:" & "$H" & "$" &
row
'x1.ActiveSheet .PageSetup.Pape rSize = xlPaperA4
'x1.ActiveSheet .PageSetup.Sort = column1

*************** *************** *************** *******

R.MoveNext
Loop
R.Close
D.Close

excelwksXL.rang e(excelwksXL.Ce lls(1, 1), _
excelwksXL.Cell s(1, row)).Select
x1.Selection.En tireColumn.Auto Fit
Set excelwbkXL = Nothing
Set excelwksXL = Nothing

'***AIM-End Message
msgbox "Transfered over " & strTable & " tables out of 31 in
total.", vbInformation

Exit_Export_Exc el_10:
Exit Function

Err_Export_Exce l_10:
msgbox ERR.Description
Resume Exit_Export_Exc el_10

End Function
Nov 13 '05 #1
0 2942

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3388
by: Guy Incognito | last post by:
Hello, I've written an asp.net application that creates Excel documents. It works by creating an excel document in XML format. But I wonder if I'm reinventing the wheel. I know that there are ways to read and write Excel files with ADO, but as far as I can tell, it doesn't provide the flexibility I need. I need to be able to generate tabs, cell formatting, formulas, etc.
3
10202
by: Otie | last post by:
I am trying to copy the cell contents in an MSFLXGRD control (using VB5) into Excel, retaining the foreground colors of the text and numbers. I have tried using the Clipboard.SetText msflxgrd1.Clip command, but that ignores the colors. I have tried to write rtf-coded text to the clipboard using: Clipboard.SetText rtf_Text, -16639
12
5538
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000 and office XP components installed. ie I have word/access/excel 2k/xp/2003 installed. I tried to do a usual access 2k to word 2k automation yet I get the error "Automation Error" "ClassFactory cannot supply requested class" when on late binding try...
8
8092
by: Colleyville Alan | last post by:
I have been working on an Access app that takes info from a file and writes it to a spreadsheet on a form, simultaneously saving the spreadsheet to Excel. I got the idea that the same concept could work in reverse, i.e. we have a cost model written in Excel that calculates the profitability of customer accounts based on several inputs and they need to be updated at least once per year. These cost models sit on lots of people's hard...
11
4057
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it again, Excel hangs. OR if I open Excel again (say from a desktop icon) before I close Access, Excel hangs. (this has happened for both 97 & 2000 for me) I of course thought that I mustn't be unloading a variable properly.
8
3539
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At the moment the printed output is usually going to Word. It's turning into an unholy mess, because I'm having to prepare umpteen different Word templates, and the queries that drive them, depending on what events a course has.
17
6348
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
12
2434
by: D. Shane Fowlkes | last post by:
This most likely belongs in another forum but I thought I'd start here. I have a COM Object written in VB6. The DLL will access MS Excel and use it's Object Library to write a customized report and saves it to a folder. The DLL even writes to a log for each step it takes so we can troubleshoot the problems (if any). This works fine on one machine but not another. The folder the DLL is trying to write to has full permissions assigned...
3
7427
by: Jennyfer Barco | last post by:
Hello, I have a question, how can I open Microsoft Excel from .NET. I only need to open a new file in Excel and paste some information and set the Microsoft Excel as the enabled aplication, so the user can continue working in Excel and he'll save the information I pasted. I tried this but doesn't open Excel at all, but it does save the file c:\test.xls with the value "This is column B row 2" in colum B and row 2: Dim xlApp As...
0
10469
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10246
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10209
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
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7560
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6803
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
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3750
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2934
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.