473,404 Members | 2,174 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,404 software developers and data experts.

Alter a Created Spreadsheet After Export

121 100+
I have a process that exports a set of records from Access to a Spreadsheet. I would like to hide the second row if possible.

Is there a way to do this through VB?


Thanks for any help I can get.
May 6 '07 #1
6 2291
JHNielson
121 100+
This is my current code:

Expand|Select|Wrap|Line Numbers
  1. Private Function Connect(ByVal strVvPathAndFileNameOfExcelSpreadsheet As String) As Boolean
  2. ' Make and open a connection to a given Excel spreadsheet
  3.  
  4.   Set cnMvConnection = New ADODB.Connection
  5.   With cnMvConnection
  6.     .Provider = "Microsoft.Jet.OLEDB.4.0"
  7.     .ConnectionString = "Data Source=" & strVvPathAndFileNameOfExcelSpreadsheet & ";Extended Properties=Excel 8.0;"
  8.     .Open
  9.     .Sheets("ERR_REPRT").Select
  10.     .Rows("2:2").Select
  11.     .Selection.Entirerow.Hidden = True
  12.   End With
  13.  
  14.  
  15. End Function
  16.  
  17. Function CHANGE_XLS()
  18.  
  19.  
  20. Call Connect("C:\TEST.xls")
  21. End Function
But I get an "Arguments are of the wrong type, are out of acceptable range or in direct conflict with another...." error
May 6 '07 #2
ADezii
8,834 Expert 8TB
This is my current code:

Expand|Select|Wrap|Line Numbers
  1. Private Function Connect(ByVal strVvPathAndFileNameOfExcelSpreadsheet As String) As Boolean
  2. ' Make and open a connection to a given Excel spreadsheet
  3.  
  4.   Set cnMvConnection = New ADODB.Connection
  5.   With cnMvConnection
  6.     .Provider = "Microsoft.Jet.OLEDB.4.0"
  7.     .ConnectionString = "Data Source=" & strVvPathAndFileNameOfExcelSpreadsheet & ";Extended Properties=Excel 8.0;"
  8.     .Open
  9.     .Sheets("ERR_REPRT").Select
  10.     .Rows("2:2").Select
  11.     .Selection.Entirerow.Hidden = True
  12.   End With
  13.  
  14.  
  15. End Function
  16.  
  17. Function CHANGE_XLS()
  18.  
  19.  
  20. Call Connect("C:\TEST.xls")
  21. End Function
But I get an "Arguments are of the wrong type, are out of acceptable range or in direct conflict with another...." error
I do believe that your syntax is all wrong. The Error occurs on
Expand|Select|Wrap|Line Numbers
  1. .Sheets("ERR_REPRT").Select
and will also occur on subsequent lines given a chance since you are attempting to reference Excel Objects (Rows, Sheets, Selection) from an ADODB Connection Object. I can't see how this could ever be successful. Your best bet may be to Export the Spreadsheet via VBA's TransferSpreadsheet Method, create an Automation Session with Excel, hide the appropriate Range, then Save your work and end the Automation Session with Excel.
May 7 '07 #3
JConsulting
603 Expert 512MB
This seems to work well enough. It will bomb if you run it twice, because row 1 is already hidden at that point.

This requires that you have your Excel reference checked in your VBA references in Access.

you can modify to suit..this code is applied to sheet 1, but can be modified to use any sheet name.

Function HideRow(sFile As String) As String
Dim xlApp As Object
Dim xlWb As Object
Dim xlWS As Worksheet
Dim strSheet As String
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open(sFile, True)
Set xlWS = xlWb.Sheets(1)
xlApp.Visible = True
xlWS.Rows("1:1").Select
Selection.EntireRow.Hidden = True
xlWb.Close (True) '<saves it
xlApp.Quit
End Function
May 7 '07 #4
JHNielson
121 100+
This seems to work well enough. It will bomb if you run it twice, because row 1 is already hidden at that point.

This requires that you have your Excel reference checked in your VBA references in Access.

you can modify to suit..this code is applied to sheet 1, but can be modified to use any sheet name.

Function HideRow(sFile As String) As String
Dim xlApp As Object
Dim xlWb As Object
Dim xlWS As Worksheet
Dim strSheet As String
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open(sFile, True)
Set xlWS = xlWb.Sheets(1)
xlApp.Visible = True
xlWS.Rows("1:1").Select
Selection.EntireRow.Hidden = True
xlWb.Close (True) '<saves it
xlApp.Quit
End Function

Great! Looks good. I will try as soon as I get a chance.

Thanks
May 7 '07 #5
JHNielson
121 100+
This seems to work well enough. It will bomb if you run it twice, because row 1 is already hidden at that point.

This requires that you have your Excel reference checked in your VBA references in Access.

you can modify to suit..this code is applied to sheet 1, but can be modified to use any sheet name.

Function HideRow(sFile As String) As String
Dim xlApp As Object
Dim xlWb As Object
Dim xlWS As Worksheet
Dim strSheet As String
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open(sFile, True)
Set xlWS = xlWb.Sheets(1)
xlApp.Visible = True
xlWS.Rows("1:1").Select
Selection.EntireRow.Hidden = True
xlWb.Close (True) '<saves it
xlApp.Quit
End Function
Sorry it took me so long to get back to you, but I tried it, and it gets me close, but when it goe to execute the " Selection.EntireRow.Hidden = True"
I get an error: "Object doesn't support this property or method."

Any ideas?

Also, I was trying to add another step here, so Itred this code ot change the row to blue:

Expand|Select|Wrap|Line Numbers
  1. Function HideRow()
  2.     Dim xlApp As Object
  3.     Dim xlWB As Object
  4.     'Dim xlWS As Worksheet
  5.     Dim strSheet As String
  6.     Set xlApp = CreateObject("Excel.Application")
  7.     Set xlWB = xlApp.Workbooks.Open("C:\Test.xls", True)
  8.     Set xlWS = xlWB.Sheets(1)
  9.     xlApp.Visible = True
  10.  
  11.         With xlWS
  12.             xlWS.Rows("1:1").Select
  13.             Selection.ColorIndex = 55
  14.                     .Pattern = xlSolid
  15.                     .PatternColorIndex = xlAutomatic
  16.  
  17.             'xlWS.Selection.EntireRow.Hidden = True
  18.         End With
  19.  
  20.     xlWB.Close (True) '<saves it
  21.     xlApp.Quit
  22. End Function
Now I get an object required and it stops at "Selection.Colorindex = 55".

Any ideas?

Thanks for everyone's help....
May 14 '07 #6
JConsulting
603 Expert 512MB
Sorry it took me so long to get back to you, but I tried it, and it gets me close, but when it goe to execute the " Selection.EntireRow.Hidden = True"
I get an error: "Object doesn't support this property or method."

Any ideas?

Also, I was trying to add another step here, so Itred this code ot change the row to blue:

Expand|Select|Wrap|Line Numbers
  1. Function HideRow()
  2.     Dim xlApp As Object
  3.     Dim xlWB As Object
  4.     'Dim xlWS As Worksheet
  5.     Dim strSheet As String
  6.     Set xlApp = CreateObject("Excel.Application")
  7.     Set xlWB = xlApp.Workbooks.Open("C:\Test.xls", True)
  8.     Set xlWS = xlWB.Sheets(1)
  9.     xlApp.Visible = True
  10.  
  11.         With xlWS
  12.             xlWS.Rows("1:1").Select
  13.             Selection.ColorIndex = 55
  14.                     .Pattern = xlSolid
  15.                     .PatternColorIndex = xlAutomatic
  16.  
  17.             'xlWS.Selection.EntireRow.Hidden = True
  18.         End With
  19.  
  20.     xlWB.Close (True) '<saves it
  21.     xlApp.Quit
  22. End Function
Now I get an object required and it stops at "Selection.Colorindex = 55".

Any ideas?

Thanks for everyone's help....

Often when using excel automation...the code runs faster than Excel does.

Place this at the top of a Code Module.

Expand|Select|Wrap|Line Numbers
  1. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  2.  
Now use this as a model to place the "Sleep" into your code...it will give Excel time to catch up.

Expand|Select|Wrap|Line Numbers
  1. Function HideRow(sFile As String) As String
  2.     Dim xlApp As Object
  3.     Dim xlWb As Object
  4.     Dim xlWS As Worksheet
  5.     Dim strSheet As String
  6.     Set xlApp = CreateObject("Excel.Application")
  7.     Set xlWb = xlApp.Workbooks.Open(sFile, True)
  8.     Set xlWS = xlWb.Sheets(1)
  9.     xlApp.Visible = True
  10.     xlWS.Rows("1:1").Select
  11.     Sleep (2000)
  12.     Selection.EntireRow.Hidden = True
  13.     xlWb.Close (True) '<saves it
  14.     xlApp.Quit
  15. End Function
  16.  
J
May 14 '07 #7

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

Similar topics

2
by: cpeters5 | last post by:
Deaa group, I am using SQLServer 2000 in an XP Sp2. I would like to do the following: I have a program running on a database server that generates some data which are loaded to the database....
2
by: Regnab | last post by:
I've got my code working so that it'll count the number of columns in the table and move across (eg Range A-P and then range Q-W). Problem is when I get to the end of the single letters and get...
4
by: Dixie | last post by:
I have a spreadsheet that uses VBA code in Access to save itself as a text file. The line is as follows. xl.ActiveSheet.SaveAs CurrentProject.Path & "\Reports\" & DLookup("", "tblButtons",...
3
by: Scott M. Lyon | last post by:
I'm trying to figure out a way to export data (actually the result of a Stored Procedure call from SQL Server) into a specified Excel spreadsheet format. Currently, I have the data read into a...
0
by: JLuv | last post by:
What i want to do is take the checked data from a datagrid, send it to a table, then show that table on an Excel Spreadsheet. Here is a little bit of my code... //adminProgress.aspx...
3
by: JHNielson | last post by:
I have a process that exports a set of records from Access to a Spreadsheet. I would like to hide the second row if possible. Is there a way to do this through VB? Thanks for any help I can...
2
by: nofear | last post by:
I used to export my reports as snapshot but now I have to export them to Excel When I export my report to a Excel Spreadsheet the report header and footer are not included Only the data gets...
2
by: wstsoi | last post by:
hi I have to read images from spreadsheet, is it possible to do with php?
4
by: JenavaS | last post by:
I am trying to create a macro to change a data type in a column. The table was created using a "make-table" query, and the column(s) I want to modify were created using a calculation in my query. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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...
0
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,...
0
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...
0
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...

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.