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.
6 2291
This is my current code: - Private Function Connect(ByVal strVvPathAndFileNameOfExcelSpreadsheet As String) As Boolean
-
' Make and open a connection to a given Excel spreadsheet
-
-
Set cnMvConnection = New ADODB.Connection
-
With cnMvConnection
-
.Provider = "Microsoft.Jet.OLEDB.4.0"
-
.ConnectionString = "Data Source=" & strVvPathAndFileNameOfExcelSpreadsheet & ";Extended Properties=Excel 8.0;"
-
.Open
-
.Sheets("ERR_REPRT").Select
-
.Rows("2:2").Select
-
.Selection.Entirerow.Hidden = True
-
End With
-
-
-
End Function
-
-
Function CHANGE_XLS()
-
-
-
Call Connect("C:\TEST.xls")
-
End Function
But I get an "Arguments are of the wrong type, are out of acceptable range or in direct conflict with another...." error
This is my current code: - Private Function Connect(ByVal strVvPathAndFileNameOfExcelSpreadsheet As String) As Boolean
-
' Make and open a connection to a given Excel spreadsheet
-
-
Set cnMvConnection = New ADODB.Connection
-
With cnMvConnection
-
.Provider = "Microsoft.Jet.OLEDB.4.0"
-
.ConnectionString = "Data Source=" & strVvPathAndFileNameOfExcelSpreadsheet & ";Extended Properties=Excel 8.0;"
-
.Open
-
.Sheets("ERR_REPRT").Select
-
.Rows("2:2").Select
-
.Selection.Entirerow.Hidden = True
-
End With
-
-
-
End Function
-
-
Function CHANGE_XLS()
-
-
-
Call Connect("C:\TEST.xls")
-
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 - .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.
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
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
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: - Function HideRow()
-
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("C:\Test.xls", True)
-
Set xlWS = xlWB.Sheets(1)
-
xlApp.Visible = True
-
-
With xlWS
-
xlWS.Rows("1:1").Select
-
Selection.ColorIndex = 55
-
.Pattern = xlSolid
-
.PatternColorIndex = xlAutomatic
-
-
'xlWS.Selection.EntireRow.Hidden = True
-
End With
-
-
xlWB.Close (True) '<saves it
-
xlApp.Quit
-
End Function
Now I get an object required and it stops at "Selection.Colorindex = 55".
Any ideas?
Thanks for everyone's help....
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: - Function HideRow()
-
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("C:\Test.xls", True)
-
Set xlWS = xlWB.Sheets(1)
-
xlApp.Visible = True
-
-
With xlWS
-
xlWS.Rows("1:1").Select
-
Selection.ColorIndex = 55
-
.Pattern = xlSolid
-
.PatternColorIndex = xlAutomatic
-
-
'xlWS.Selection.EntireRow.Hidden = True
-
End With
-
-
xlWB.Close (True) '<saves it
-
xlApp.Quit
-
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. -
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
-
Now use this as a model to place the "Sleep" into your code...it will give Excel time to catch up. -
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
-
Sleep (2000)
-
Selection.EntireRow.Hidden = True
-
xlWb.Close (True) '<saves it
-
xlApp.Quit
-
End Function
-
J
Sign in to post your reply or Sign up for a free account.
Similar topics
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....
|
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...
|
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",...
|
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...
|
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...
|
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...
|
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...
|
by: wstsoi |
last post by:
hi
I have to read images from spreadsheet, is it possible to do with php?
|
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. ...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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: 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,...
|
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...
|
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...
| |