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 7950225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:12:18+00:00 2026-06-04T02:12:18+00:00

Here’s what I’m trying to do and I apologize if I’m headed the wrong

  • 0

Here’s what I’m trying to do and I apologize if I’m headed the wrong direction. I’m trying to cycle through the filepath’s stored in table t_Directory and if the file extension is “xlsx” open the Excel file and update another table called t_SheetInfo with the FileID of the Excel Worksheet and sheet count and the sheet name. Would anyone have a minute to check what I’ve got so far or steer me in the right direction if there’s a more efficient way to do it? I’m not 100% sure that I know what I’m doing. As always, thank you in advance for any help!!

Dim db As DAO.Database
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet

Private Sub CycleThroughWorkSheets()
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim sSQL1 As String
Dim sSQL2 As String
Dim sSQL3 As String
Dim rsFilePath As String
Dim rsWSName As String

Set db = CurrentDB

sSQL1 = "SELECT t_Directory.FileID, t_Directory.FilePath FROM t_Directory " & _
        "WHERE (((t_Directory.FileExtension)=""'xlsx'""))"
Set rs = db.OpenRecordset("sSQL1", dbOpenDynaset)
    With rs
        rs.MoveFirst
            Do While Not rs.EOF
                rsFilePath = rs.Fields("[FilePath]")
                OpenWorkBook (rsFilePath)
Set rs2 = db.OpenRecordset("t_SheetInfo", dbOpenDynaset)
    With rs2
        rs2.MoveFirst
            Do While Not rs2.EOF
                rs2.AddNew
                rs2.Fields("FileID") = rs.Fields(1)
                rs2.Fields("[SheetIndex]") = WorkSheetCount(rsFilePath)
                rs2.Fields("[SheetName]") = WorkSheetName(WorkSheetCount)
                rs2.Update
            Next
            Loop
    End With
    End With
Set rs = Nothing
Set rs2 = Nothing
End Sub

Public Function WorkSheetCount(rsFilePath As String) As Integer
Set xlWB = xlApp.Workbooks.Open(rsFilePath)
      WorkSheetCount = xlWB.Sheets.Count(rsFilePath)
      Debug.Print "WorkSheetCount : " & WorkSheetCount
End Function

Public Function WorkSheetName(WorkSheetCount As Integer) As String
Set xlWB = xlApp.Workbooks.Open(rsFilePath)
      WorkSheetName = Worksheets(WorkSheetCount).Name
      Debug.Print "WorkSheetName : " & WorkSheetName
End Function
  • 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-06-04T02:12:19+00:00Added an answer on June 4, 2026 at 2:12 am

    Try something on these lines. Step through.

    Dim xlApp As New Excel.Application
    Dim xlWB As Excel.Workbook
    Dim sh As Object ''Some sheets may be charts
    Dim rs As DAO.Recordset
    Dim rs2 As DAO.Recordset
    Dim sSQL1 As String
    Dim sSQL2 As String
    Dim sSQL3 As String
    Dim rsFilePath As String
    Dim rsWSName As String
    
    Set db = CurrentDb
    xlApp.Visible = True
    
    sSQL1 = "SELECT t_Directory.FileID, t_Directory.FilePath FROM t_Directory " & _
            "WHERE t_Directory.FileExtension='.xlsx'"
    Set rs2 = db.OpenRecordset("t_SheetInfo", dbOpenDynaset)
    
    Set rs = db.OpenRecordset(sSQL1, dbOpenDynaset)
    Do While Not rs.EOF
        rsFilePath = rs.Fields("[FilePath]")
        Set xlWB = xlApp.Workbooks.Open(rsFilePath)
    
        For Each sh In xlWB.Sheets
            rs2.AddNew
            rs2.Fields("FileID") = rs.Fields("FileID")
            rs2.Fields("[SheetIndex]") = sh.Index
            rs2.Fields("[SheetName]") = sh.Name
            rs2.Update
        Next
        rs.MoveNext
        xlWB.Close False
    Loop
    Set rs = Nothing
    Set rs2 = Nothing
    xlApp.Quit
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's what I want to do: Given a table PeopleOutfit (id int primary key,
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the css: #content ul { font-size: 12px; } I am trying this:
Here's an example query: DECLARE @table table (loc varchar(10)) INSERT INTO @table VALUES ('134a'),
Here is the problem that I am trying to solve. I have two folders
Here's what I'm doing. I want to upload multipart file via Ajax to my
Here's what my table TheTable looks like ColA | ColB | ColC ------+-------+------ abc
Here's the flow that I am trying to achieve: 1) User uploads an audio
Here is what I am trying to achieve in PHP: I have this string:
Here's what I'm trying to do... It's quite simple and obviously there must be

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.