excel - VBA Reptitive MDX query to Analysis Services -
i have report run same mdx query each week, , paste results in worksheet generate report. know how connect olap cube in excel, don't manipulating pivot table match query.
i'd use vba connect cube , and return results of specific query in worksheet values paste, or table. can save mdx query in seperate sheet. possible? i'm new vba, i'm not sure started. example code great.
i think previous question pretty need:
any mdx query within excel vba?
i adapted code in previous question-answer wrote following seems return number ok:
sub getfromcube() dim strconn string strconn = _ "provider=msolap.6;" & _ "data source=imxxxxxx;" & _ '<<<name of server here "initial catalog=adventureworksdw2012multidimensional-ee;" & _ '<<<name of adv wrks db here "integrated security=sspi" dim pubconn adodb.connection set pubconn = new adodb.connection pubconn.commandtimeout = 0 pubconn.open strconn dim cs adomd.cellset set cs = new adomd.cellset dim mymdx string mymdx = _ " select" & _ " non empty" & _ " [customer].[customer geography].[state-province].&[ab]&[ca] on 0," & _ " non empty" & _ " [measures].[internet sales amount] on 1" & _ " [adventure works];" cs .open mymdx, pubconn activesheet.range("a1") = cs(0, 0) .close end end sub
if in previous question see getting hold of cellset of data quite easy pasting worksheet not trivial. simplicity , check things working expected used activesheet.range("a1") = cs(0, 0)
. think need loop through cellset.
note - need add 2 references above work:
- microsoft activex data objects 6.1 library
- microsoft activex data objects (multi-dimensional) 6.0 library
(or latest version of each have available)
Comments
Post a Comment