formatere excel-eksport vha. VBA?
Er det muligt - og i såfald hvordan - vha. VBA at formatere felterne som man "eksporterer" til i excel fra access.Jeg benytter noget a'la det her til at eksportere fra access til excel - og det virker fint. Problemet er at jeg så gerne vil kunne bestemme baggrundsfarven, række-bredden, skrifttypen etc. på felterne i excel...
Function goXL()
Dim objXL As Object
Dim strWhat As String, boolXL As Boolean
Dim objActiveWkb As Object
If fIsAppRunning("Excel") Then
Set objXL = GetObject(, "Excel.Application")
boolXL = False
Else
Set objXL = CreateObject("Excel.Application")
boolXL = True
End If
objXL.Application.workbooks.Add
Set objActiveWkb = objXL.Application.ActiveWorkBook
strSQL = "SELECT *,YEAR([startdato]) as startYear,Month([startdato]) as startMonth,DAY([startdato]) as startDay,YEAR([slutdato]) as slutYear,Month([slutdato]) as slutMonth,DAY([slutdato]) as slutDay FROM [soekontrol]"
Dim i, j As Integer
i = 2
Set RSTKontrol = CurrentDb.OpenRecordset(strSQL)
Do While Not RSTKontrol.EOF
j = 1
With objActiveWkb
.Worksheets(1).Cells(i, 1) = RSTKontrol!soenavn
.Worksheets(1).Cells(i, 2) = RSTKontrol!startdato
.Worksheets(1).Cells(i, 2) = RSTKontrol!starttime & ":" & RSTKontrol!startmin
strWhat = .Worksheets(1).Cells(1, 1).Value
End With
RSTKontrol.MoveNext
Loop
' objActiveWkb.Close savechanges:=False
If boolXL Then objXL.Application.Quit
Set objActiveWkb = Nothing: Set objXL = Nothing
MsgBox strWhat
End Function
