+ Reply to Thread
Results 1 to 3 of 3

Thread: CONVERT Excel Macro to Access?

  1. #1
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    60

    Exclamation CONVERT Excel Macro to Access?

    Hello,

    Can someone please help me convert this macro that was initially written for Excel into a functioning Access macro? I would still like to pull data from the source excel workbooks, but simply make an access database the destination.

    Thank you

    Sub datacollect()
      
    Dim C As Long
      Dim DstWks1 As Worksheet
      Dim LastCol As Variant
      Dim LastRow As Long
      Dim R As Long
      Dim SrcWkb As Workbook
      Dim StartRow As Long
      Dim wkbname As Variant
      Dim xlsFiles As Variant
      
       'Starting column and row for the destination workbook
        C = 2
        R = 2
       'Set references to destination workbook worksheet objects
        Set DstWks1 = ThisWorkbook.Worksheets("Data")
        
       'Starting row on source worksheet
        StartRow = 1
        
       'Get the workbooks to open
        xlsFiles = Application.GetOpenFilename(FileFilter:="Excel files (*.xls), *.xls", MultiSelect:=True)
        Application.AskToUpdateLinks = False
          If VarType(xlsFiles) = vbBoolean Then Exit Sub
          
         'Loop through each workbook and copy the data to this workbook
          For Each wkbname In xlsFiles
            Set SrcWkb = Workbooks.Open(Filename:=wkbname, ReadOnly:=True)
              Set LastCol = SrcWkb.Worksheets("Equity").Cells.Find("*", , xlValues, xlPart, xlByColumns, xlPrevious, False)
              If Not LastCol Is Nothing Then LastCol = LastCol.Column Else
              LastRow = SrcWkb.Worksheets("Equity").Cells(Rows.Count, LastCol).End(xlUp).Row
                If LastRow >= StartRow Then
                  With SrcWkb.Worksheets("Equity")
                    DstWks1.Cells(R, C).Resize(LastRow - StartRow + 1, 1).Value = _
                    .Range(.Cells(StartRow, LastCol), .Cells(LastRow, LastCol)).Value
                  End With
          'Pulls the pertrac ID number located on the first page of each template
                With SrcWkb.Worksheets("Data Entry")
                    DstWks1.Cells(1, C).Value = _
                      .Cells(1, 13).Value
                  End With
                End If
          
         
          
            C = C + 1
    Continue:
            SrcWkb.Close savechanges:=False
          Next wkbname
    
    End Sub

  2. #2
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,029

    Re: CONVERT Excel Macro to Access?

    Hi, could you post an example of one of the source data workbooks?

  3. #3
    Forum Guru davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2007
    Posts
    1,879

    Re: CONVERT Excel Macro to Access?

    It'd be much easier just to import the data from the destination workbook into Access. Otherwise you'll have to work with recordsets and arrays.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0