Formatting outputted Excel files from Access using VBA?

后端 未结 4 731
面向向阳花
面向向阳花 2021-01-03 17:01

Here I have some VBA code that outputs a ton of files into Excel files. My question is, from this, is there anyway for it to Format the excel file a bit? What I would like t

4条回答
  •  独厮守ぢ
    2021-01-03 17:18

    Yes it is possible! This is hacked together from one of my codes, might need a bit of editing before it works...

    'This deals with Excel already being open or not
    On Error Resume Next
    Set xl = GetObject(, "Excel.Application")
    On Error GoTo 0
    If xl Is Nothing Then
      Set xl = CreateObject("Excel.Application")
    End If
    
    Set XlBook = GetObject(filename)
    'filename is the string with the link to the file ("C:/....blahblah.xls")
    
    'Make sure excel is visible on the screen
    xl.Visible = True
    XlBook.Windows(1).Visible = True
    'xl.ActiveWindow.Zoom = 75
    
    'Define the sheet in the Workbook as XlSheet
    Set xlsheet1 = XlBook.Worksheets(1)
    
    'Then have some fun!
    with xlsheet1
        .range("A1") = "some data here"
        .columns("A:A").HorizontalAlignment = xlRight
        .rows("1:1").font.bold = True
    end with
    
    'And so on...
    

提交回复
热议问题