我有一个连接到数据库的essbase宏,我在xml文件中有3个服务器详细信息,我必须为它设置一个活动标志,这样当它说" Y" ,它必须连接宏与特定的服务器详细信息,请让我知道任何输入
=============================================== =======================
Sub ImportXMLtoList()
Dim strTargetFile As String
Dim wb As Workbook
application.ScreenUpdating = False
application.DisplayAlerts = False
strTargetFile = "C:\Users\raji\Desktop\LoginDetails.xml"
Set wb = Workbooks.OpenXML(Filename:=strTargetFile, LoadOption:=xlXmlLoadImportToList)
application.DisplayAlerts = True
wb.Sheets(1).UsedRange.Copy ThisWorkbook.Sheets("Sheet1").range("A1")
wb.Close False
application.ScreenUpdating = True
Dim r As Long, endRow As Long, pasteRowIndex As Long
endRow = 5
pasteRowIndex = 1
For r = 1 To endRow
If Cells(r, Columns("F").Column).Value = "Y" Then 'Found
Rows(r).Select
Selection.Copy
Sheets("Sheet2").Select
Rows(pasteRowIndex).Select
ActiveSheet.Paste
Sheets("Sheet1").Select
End If
Next r
从这段代码中我可以从XML调用数据,并且Active标志已设置为Y,我可以将其写入下一页
现在我正在尝试将行数据调用到EssvConnect
Set myusername = Sheet2.range("B1")
Set mypassword = Sheet2.range("C1")
Set myServer = Sheet2.range("A1")
Set myApp = Sheet2.range("D1")
Set myDB = Sheet2.range("E1")
x = EssVConnect("[Book1.xls] Sheet6", "myusername", "mypassword", "myServer", "myApp", "myDB")
range("A1:P35").Select
application.Run macro:="EssMenuRetrieve"
当我尝试运行此操作时,我收到错误"需要对象",请帮助我
提前致谢
请使用以下代码并且工作正常
Sheets("Sheet2").Activate
myUserName = ActiveSheet.Cells(1, 2)
myPassword = ActiveSheet.Cells(1, 3)
myServer = ActiveSheet.Cells(1, 1)
myApp = ActiveSheet.Cells(1, 4)
myDB = ActiveSheet.Cells(1, 5)
x = EssVConnect("[Book1.xls] Sheet6", myUserName, myPassword, myServer, myApp, myDB)
Sheets("Sheet6").Select
range("A1:P35").Select
application.Run macro:="EssMenuRetrieve"
答案 0 :(得分:0)
看看这里:Using Essbase VBA Functions
Sub Conn()
X=EssVConnect(Empty, "User1", "password", "Local", "Sample", "Basic")
'or
'X=EssVConnect("[SAMPVBA.XLS]", "USER1", "PASSWORD", "LOCAL", "Sample", "Basic")
End Sub
您可以在此处找到更多内容:Essbase - library of VBA functions for use in Excel