Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 05-26-2015, 10:25 AM
charlesdh charlesdh is offline Path issue using a macro on the ribbon Windows 7 32bit Path issue using a macro on the ribbon Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

Why not make a stand-alone file for the Macro and then have the code to allow you to open the desired workbook for you too update. You can then do a save as for the workbook.
In the files that you are updating you do not need a macro.

In the code below you can see what I did that allow the user to ope multiple workbooks to update.
This may help you.

Code:
Option Explicit
Public Mystore As String
Public MYdate As String
Public Mysales As String
Sub Gather_Data()
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim s
Dim Store As Variant ''' store nr
Dim Sdate As Variant ''' sales date
Dim Dwb As Workbook '' for daily balance
Dim LFwb As Workbook
Dim SSwb As Workbook
Dim fd As FileDialog
Dim Myfile As String
Dim Mypath As String
Dim lngCount As Long
Dim mysrow As Long
Dim mydcol As Long
Dim Rlrow As Long
'Create a FileDialog object as a File Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    'Declare a variable to contain the path
    Mypath = ThisWorkbook.Path
    'Use a With...End With block to reference the FileDialog object.
    With fd
        'Use the Show method to display the File Picker dialog box and return the user's action.
        'The user pressed the action button.
        ''''''''''''''''''''''''
        .AllowMultiSelect = True
        If .Show = -1 Then
            For lngCount = 1 To .SelectedItems.Count
                Myfile = .SelectedItems(lngCount)
                Workbooks.Open (Myfile)
                If InStr(ActiveWorkbook.Name, "SALES") <> 0 Then
                    Set SSwb = ActiveWorkbook
                ElseIf InStr(ActiveWorkbook.Name, "Long") <> 0 Then
                    Set LFwb = ActiveWorkbook
                ElseIf InStr(ActiveWorkbook.Name, "Daily") <> 0 Then
                    Set Dwb = ActiveWorkbook '''' Daily workbook
                End If
            Next lngCount
        'The user pressed Cancel.
        Else
            Exit Sub
        End If
    End With
    'Set the object variable to Nothing. Unloads from memory
    Set fd = Nothing
    '''' Open Daily Balance workbook'''
    Dwb.Activate
    ''' Get the Store Nr. and Date ''
    Mysales = ActiveSheet.Range("C3")
    MYdate = ActiveSheet.Range("G1")
    Mystore = ActiveSheet.Range("C1")
    '''' Activate Sales '''
    SSwb.Activate
    ''' Find Store and date to populate the data ''
    With ActiveSheet.UsedRange
        Set Sdate = .Find(MYdate, lookat:=xlPart) ''' find date to get the row nr and column
        If Not Sdate Is Nothing Then
        ''' Date found ''''
            mydcol = Sdate.Column
        End If
    End With
    Rlrow = ActiveSheet.Range("A" & Sdate.Row + 1).End(xlDown).Row
    With Range("A" & Sdate.Row + 1 & ":" & "A" & Rlrow)
    '''' Find the Store and then the date '''
        Set Store = .Find(Mystore, lookat:=xlPart)
            If Not Store Is Nothing Then
            '''' Store found '''
                mysrow = Store.Row
                ''' Populate the Data
            ActiveSheet.Cells(mysrow, mydcol).Value = Mysales
            End If
    End With
    LFwb.Activate ''' open the "Long Form ''''
    With ActiveSheet.UsedRange
    '''' Find the Store and then the date '''
        Set Store = .Find(Mystore, lookat:=xlPart)
            If Not Store Is Nothing Then
            '''' Store found Populate the data'''
                ActiveSheet.Cells(Store.Row, 2).Value = Mysales
            End If
    End With
End Sub
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Path issue using a macro on the ribbon Ribbon issue kmac Word 3 01-09-2015 04:05 PM
Is it possible to add a custom macro button to the FILE tab of the ribbon in excel sbapabck Excel 2 04-11-2014 07:36 AM
How to import the customized ribbon to Word without overwriting the existing Ribbon? SharonSh Word VBA 0 09-26-2013 11:47 PM
Excel 2010 Ribbon look like 2007's Ribbon esotop Excel 0 03-22-2011 07:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:20 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft