Generating Workbooks for each record in a recordset?

etk

Registered User.
Local time
Today, 02:04
Joined
May 21, 2011
Messages
52
Is is possible to generate a workbook for each record in a recordset, and title it using the unique identifier for that record?

I created the following code, but it does not seem to work. First of all it doesnt like the string and secondly it does not like the declaration of wb as Excel.Application

any thoughts or better approaches?

Code:
Private Sub generate_wkbk()
Dim rsID As DAO.Recordset
Set rsID = CurrentDb.OpenRecordset("Select * FROM tblMeeeting;", dbOpenDynaset)
 
    With rsID
        rsID.MoveFirst
        Do Until rsID.EOF
                  
             Dim filepath As String
             Set filepath = "\Desktop\test\Data_for_Meeting_#" & rsID!Meeting_ID & ".xls"
             Dim wb As Excel.Application
             Dim mywb As Excel.Workbook
             Set wb = CreateObject("Excel.Application")
             Set mywb = GetObject(filepath)
        Loop
    End With
    
    rsID.Close
    Set rsID = Nothing
            
End Sub
 
You need to set references to Excel.
Open your VBA-code window, click on "Tools" in the menu line, choose "References", mark "Microsoft Excel X.X Object library" in the list, (X.X = version no).
You also need a rsID.MoveNext in your loop.
 
You need to set references to Excel.
Open your VBA-code window, click on "Tools" in the menu line, choose "References", mark "Microsoft Excel X.X Object library" in the list, (X.X = version no).
You also need a rsID.MoveNext in your loop.

I deleted the MoveNext by accident when modifying it to put up on the forum. The Excel object libarary 14.0 was turned on. I already figured that may have been the problem, but it still does not want to recognize the object.
 
Try then below, if Meeting_ID is number type:

Set filepath = "\Desktop\test\Data_for_Meeting_#" & CStr(rsID!Meeting_ID) & ".xls"

Could it be because of missing drive letter?
And you are sure the path and file name exist?
 

Users who are viewing this thread

Back
Top Bottom