+ Reply to Thread
Results 1 to 2 of 2

Resume a macro

  1. #1
    Registered User
    Join Date
    10-29-2013
    Location
    Lda, lda
    MS-Off Ver
    Excel 2007
    Posts
    1

    Resume a macro

    I have created the following macro that allows me to connect and retrieve data from database.
    instead of having 3 repeated actions, I would like to summarize it in just one
    here it goes:
    --------------
    Option Explicit
    Dim MySheet As String
    Dim MyUser As String
    Dim MyPW As String
    Dim MySrv As String
    Dim MyApp As String
    Dim MyDB As String
    Dim MyRange As String

    Public Sub Retrieve_RA1()

    MySheet = "[" & ThisWorkbook.Name & "]" & ActiveSheet.Name
    MyUser = "J0241105"
    MyPW = "Essbase"
    MySrv = "Aoeptta-Apepm61"
    MyApp = "CONSO"
    MyDB = "PROD"
    MyRange = "RA1"


    If Not Connect(MySheet, MyUser, MyPW, MySrv, MyApp, MyDB) Then
    MsgBox "Connection impossible "
    Disconnect (MySheet)
    Exit Sub
    End If

    If Not Retrieve(MySheet, MyRange) Then
    MsgBox "Retrieve impossible "
    Disconnect (MySheet)
    Exit Sub
    End If

    Disconnect (MySheet)

    End Sub
    -----------------

    Public Sub Retrieve_RA2()

    MySheet = "[" & ThisWorkbook.Name & "]" & ActiveSheet.Name
    MyUser = "J0241105"
    MyPW = "Essbase"
    MySrv = "Aoeptta-Apepm61"
    MyApp = "CONSO"
    MyDB = "PROD"
    MyRange = "RA2"


    If Not Connect(MySheet, MyUser, MyPW, MySrv, MyApp, MyDB) Then
    MsgBox "Connection impossible "
    Disconnect (MySheet)
    Exit Sub
    End If

    If Not Retrieve(MySheet, MyRange) Then
    MsgBox "Retrieve impossible "
    Disconnect (MySheet)
    Exit Sub
    End If

    Disconnect (MySheet)

    End Sub
    -------------------
    Public Sub Retrieve_RA3()

    MySheet = "[" & ThisWorkbook.Name & "]" & ActiveSheet.Name
    MyUser = "J0241105"
    MyPW = "Essbase"
    MySrv = "Aoeptta-Apepm61"
    MyApp = "CONSO"
    MyDB = "PROD"
    MyRange = "RA3"


    If Not Connect(MySheet, MyUser, MyPW, MySrv, MyApp, MyDB) Then
    MsgBox "Connection impossible "
    Disconnect (MySheet)
    Exit Sub
    End If

    If Not Retrieve(MySheet, MyRange) Then
    MsgBox "Retrieve impossible "
    Disconnect (MySheet)
    Exit Sub
    End If

    Disconnect (MySheet)

    End Sub
    ------------------
    thanks for your help

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Resume a macro

    If the only thing that changes is MyRange try this.

    Please Login or Register  to view this content.
    PS Please use code tags.
    Last edited by Norie; 11-28-2013 at 11:45 AM.
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Pausing A Macro (allow user to extract data) aAnd Resume Macro
    By jbumps in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2013, 01:59 PM
  2. [SOLVED] How to pause a macro whilst letting a web query finish and then resume macro
    By Eno in forum Excel Programming / VBA / Macros
    Replies: 33
    Last Post: 08-14-2012, 12:02 PM
  3. Stop Macro, Check Cells & Modify if Necessary, Resume Macro
    By AccountantCost in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2009, 07:39 AM
  4. Is there a way to Temp Pause and Resume a Macro?
    By 0o0o0 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-24-2006, 05:28 AM
  5. Where is the resume macro on the toolbar?
    By Bju23 in forum Excel General
    Replies: 1
    Last Post: 11-07-2005, 05:00 PM

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.6.0 RC 1