AbsoluteAccess
New member
- Local time
- Tomorrow, 06:43
- Joined
- Feb 12, 2013
- Messages
- 9
I am exporting data to a new Excel spreadsheet and everything is working ok except for the formatting on my first row. I am setting the orientation to vertical and am not having any luck with getting the text spacing correct. It is too big. This is my code:
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim xlrange As Excel.Range
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = True
'Create new workbook
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.ActiveSheet
'Set Header
xlsheet.PageSetup.Orientation = xlLandscape
xlapp.ActiveWindow.View = xlPageLayoutView
'Set Headings
xlsheet.Cells(1, 1) = "Scope type"
xlsheet.Cells(1, 2) = "Street No."
xlsheet.Cells(1, 3) = "Street Name"
xlsheet.Cells(1, 4) = "MP Number"
'Set column widths
Set xlrange = xlsheet.Range("A1
1")
With xlrange
.HorizontalAlignment = xlGeneral (This line not working)
.VerticalAlignment = xlBottom (This line not working)
.Orientation = xlVertical
End With
xlsheet.Columns(1).ColumnWidth = 4
xlsheet.Columns(2).ColumnWidth = 4
I have tried changing the constants in the relevant lines to the matching numeric values as well as to Excel.Constants.xlGeneral etc
I have also tried selecting the range before applying the code but nothing seems to be working.
If anyone can offer any assistance, I would greatly appreciate it. I'm using Access 2010.
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim xlrange As Excel.Range
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = True
'Create new workbook
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.ActiveSheet
'Set Header
xlsheet.PageSetup.Orientation = xlLandscape
xlapp.ActiveWindow.View = xlPageLayoutView
'Set Headings
xlsheet.Cells(1, 1) = "Scope type"
xlsheet.Cells(1, 2) = "Street No."
xlsheet.Cells(1, 3) = "Street Name"
xlsheet.Cells(1, 4) = "MP Number"
'Set column widths
Set xlrange = xlsheet.Range("A1

With xlrange
.HorizontalAlignment = xlGeneral (This line not working)
.VerticalAlignment = xlBottom (This line not working)
.Orientation = xlVertical
End With
xlsheet.Columns(1).ColumnWidth = 4
xlsheet.Columns(2).ColumnWidth = 4
I have tried changing the constants in the relevant lines to the matching numeric values as well as to Excel.Constants.xlGeneral etc
I have also tried selecting the range before applying the code but nothing seems to be working.
If anyone can offer any assistance, I would greatly appreciate it. I'm using Access 2010.