Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7502707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:57:46+00:00 2026-05-29T20:57:46+00:00

Using Access 2007 vba addressing an Excel 2007 workbook (WB)…. This routine adds a

  • 0

Using Access 2007 vba addressing an Excel 2007 workbook (“WB”)….

This routine adds a worksheet to an existing and open excel workbook, then adds the rows of a recordset to the sheet. It’s quite messy for now, I’m setting it up to create several sheets, all looking at the same data in different ways.

I have succeeded in posting the rows, but now I want to format them a little better to avoid confusing Excel-ignorant target users. I want to change the color of the header cells, and I want to set the columns to “autofit”.

Can anyone help?

Sub SummarySheets(WB As Excel.WorkBook, TempTableName As String)
Const SummarySheetName As String = "Timesheet Summaries"
Const SummaryQueryName As String = "qrySATempSummarybyWO"
Const SummaryTitleRow As Integer = 1


Dim xlSumSht As Excel.Worksheet
If SheetExists(WB, SummarySheetName) Then
    WB.Sheets(SummarySheetName).Delete
End If
Set xlSumSht = WB.Sheets.Add(After:=WB.Sheets(WB.Sheets.count))
xlSumSht.NAME = SummarySheetName
xlSumSht.Activate

Dim intRow As Integer
Dim intCol As Integer
Dim intStartRow As Integer
Dim strSQL As String
Dim strQry As String

Dim rstSummary As DAO.Recordset

strQry = CurrentDbC.QueryDefs(SummaryQueryName).SQL
strSQL = Replace(strQry, "tblStaffAugTrans", "[" & TempTableName & "]")

Set rstSummary = CurrentDbC.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges + dbFailOnError)
If rstSummary.EOF = False Then
    intRow = SummaryTitleRow
    For intCol = 1 To rstSummary.Fields.count
        xlSumSht.Cells(intRow, intCol).Value = rstSummary.Fields(intCol - 1).NAME
    Next intCol
End If
While rstSummary.EOF = False
    intRow = intRow + 1
    For intCol = 1 To rstSummary.Fields.count
        xlSumSht.Cells(intRow, intCol).Value = rstSummary.Fields(intCol - 1).Value
    Next intCol
    rstSummary.MoveNext
Wend
For intCol = 1 To rstSummary.Fields.count
    'xlSumSht.Columns.EntireColumn(, intCol).AutoFit
Next intCol

rstSummary.Close

End Sub

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:57:49+00:00Added an answer on May 29, 2026 at 8:57 pm

    Something like this should do the job. This will simply set the headings to have a Yellow interior colour and will auto-fit the columns.

    With xlSumSht.Range(Cells(SummaryTitleRow, 1), Cells(SummaryTitleRow, rstSummary.Fields.Count))
        .Interior.Color = vbYellow
        .EntireColumn.AutoFit
    End With
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem creating new instance of excel 2007 using VBA (from Access 2002).
i saw this topic How to show "Open File" Dialog in Access 2007 VBA?
I'm Using Excel/Access 2007. I made an Access query in Access, and I tried
I am using Access 2007 (VBA - adp) front end with a SQL Server
I'm assigning an Access 2007 query to a QueryDef in Excel VBA. My query
This is a Query in VBA (Access 2007) I have 3 strings defined: str_a
I have the following problem in a Database using Access 2007 as front end
as example, I've the following SQL query ( using Access 2007 ) SELECT ID,
Using MS Access 2007, I am creating a student management database. I have tables
I am using Microsoft Access 2007 to move and massage some data between two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.