VBA will wrap text but will not merge excel cells.

Geek65

New member
Local time
Today, 01:24
Joined
Nov 30, 2011
Messages
7
I have a report that I am exporting to Excel saving and formatting using VBA from access 2007. I have one last bit of formatting I want to accomplish. It involves applying .WrapText and .MergeCells. The excel file created from the report accepts the WrapText but will not accept the MergeCells command. I have tested the code on a Excel test file and it works on the test file but not on the one created from the report. Any Ideas?? The Book1.xls attached is the file file that will merge and the rptTest.xls will not. Here is the code:
Private Sub cmdExcelReport_Click()
Dim stDocName, strsql As String
Dim strcriteria, strfilter, strScrnFilter As String

Dim objXL As Object
Dim xlWB As Object
Dim xlSheet As Object

'****** Format routeine *********
filein = ("C:\Book1.xls")
sheetin = ("rptPOC")
'** Call sub ***
Call Fmttest
End Sub

Public Sub Fmttest()
'**************
Dim objXL As Object
Dim xlWB As Object
Dim xlSheet As Object
'*************
Set objXL = CreateObject("Excel.Application")
Set xlWB = objXL.Workbooks.Open(filein)
Set xlSheet = objXL.Sheets(sheetin)
' ***** start format *******************************
With objXL.Sheets("rptPOC").Range("A1:B1")
.WrapText = True
.MergeCells = True
End With
xlWB.Close True
objXL.Quit
End Sub

*******************
THIS DOES NOT WORK
********************
Private Sub cmdExcelReport_Click()
Dim stDocName, strsql As String
Dim strcriteria, strfilter, strScrnFilter As String

Dim objXL As Object
Dim xlWB As Object
Dim xlSheet As Object

'****** Format routeine *********
filein = ("C:\rptTest.xls")
sheetin = ("rptPOC")
'** Call sub ***
Call Ftest
End Sub

Public Sub Ftest()
'(filein As String, sheetin As String)
'**************
Dim objXL As Object
Dim xlWB As Object
Dim xlSheet As Object
'*************
Set objXL = CreateObject("Excel.Application")
Set xlWB = objXL.Workbooks.Open(filein)
Set xlSheet = objXL.Sheets(sheetin)
' ***** start format *******************************
With objXL.Sheets("rptPOC").Range("A4:B4")
.WrapText = True
.MergeCells = True
End With


' objXL.CutCopyMode = False
xlWB.Close True
objXL.Quit
End Sub
 

Attachments

Bump..HELP.... Nobody has any ideas?????????? REALLY wow. bummer.
 
I just saw this. You don't want to use

.MergeCells = True

you want:
objXL.Sheets("rptPOC").Range("A4:B4").Merge

or shortened up with your range WITH code

.Merge
 

Users who are viewing this thread

Back
Top Bottom