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
Bookmarks