tag:blogger.com,1999:blog-3174073825360154810.post7525649801646053466..comments2022-12-06T05:49:47.306-05:00Comments on QlikView Maven: Macro to Copy Cycle Group From One Document to Another-TBhttp://www.blogger.com/profile/08386812862574514289noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-3174073825360154810.post-44157326219719653442013-03-26T14:36:53.336-04:002013-03-26T14:36:53.336-04:00For anyone interested, here is the code for the ma...For anyone interested, here is the code for the macro with <i>browse-for-file</i> functionality. This only works if you have MS Office installed or MS Excel for Windows. You will also need to set Module Security and Local Security to Allow System Access (on the left side of your Edit Module window).<br /><br />Sub Copy_Cycle_Group_Doc_to_Doc<br />'------------------------------<br />' /* Copy Cycle Group From One QV Document to Another */<br />' /* Requested Module Security and Current Local Security must be set to Allow System Access */<br />' /* QlikView Maven, March 2013 */<br />Dim objQV, objSource, objDest, objSourceVar, objDestVar <br />Dim objVars, varcontent, objTempVar, varname, i, varctr<br />'initialize<br />Set objXL=CreateObject("Excel.Application")<br />fn_source=objXL.GetOpenFilename("All Files (*.qvw),*.qvw",,"Select file containing the Cycle Group you want to copy",False)<br />If fn_source="False" then<br /> 'user cancelled out of dialog box<br /> Set oXL=nothing<br /> Exit sub<br /> End If<br />'fn_source=inputbox("Enter pathname to source document containing the Cycle Group you want to copy:","Enter Source Document Pathname")<br />'if trim(fn_source)="" then 'no entry or cancel<br />' exit sub<br />' end if<br /><br />CGName=trim(inputbox("Enter name of Cycle Group to copy:","Enter Cycle Group Name"))<br />if CGName="" then 'no entry or cancel<br /> exit sub<br /> end if<br /><br />fn_dest=objXL.GetOpenFilename("All Files (*.qvw),*.qvw",,"Select document where the Cycle Group is to be inserted",False)<br />If fn_dest="False" then<br /> 'user cancelled out of dialog box<br /> Set oXL=nothing<br /> Exit sub<br /> End If<br />'fn_dest=inputbox("Enter pathname to destination document where the Cycle Group is to be inserted:","Enter Destination Document Pathname")<br />'if trim(fn_dest)="" then 'no entry or cancel<br />' exit sub<br />' end if<br />Set objSource=Application.OpenDoc(fn_source)<br />Set objDest=Application.OpenDoc(fn_dest) <br />Set SrcGrp = objSource.GetGroup(CGName)<br />Set SrcProps = SrcGrp.GetProperties<br />Set NewGrp = objDest.GetGroup(CGName)<br />If NewGrp Is Nothing Then 'check if cycle group exists in dest document<br /> Set NewGrp = objDest.CreateGroup(CGName) 'doesn't exist so create it<br />Else<br /> Set NewProps = NewGrp.GetProperties 'does exist so remove old definition<br /> for i = 1 to NewProps.FieldDefs.Count<br /> NewGrp.RemoveField 0<br /> Next<br /> End If<br />Set NewProps = NewGrp.GetProperties<br />'copy elements of cycle group from source to dest<br />NewProps.FieldDefs.CopyFrom SrcProps.FieldDefs<br />NewProps.IsCyclic = SrcProps.IsCyclic<br />NewProps.Labels = SrcProps.Labels<br />NewProps.Present = SrcProps.Present<br />NewProps.SortCriterias.CopyFrom SrcProps.SortCriterias<br />NewGrp.SetProperties NewProps<br /><br />'we're done, show a message and close down<br />x=msgbox(CGName&" copied from "&fn_source&" to "&fn_dest&"."&chr(13)&"OK to Save?",vbOKCancel,"Copy_Cycle_Group_Doc_to_Doc")<br />if x=vbOK then<br /> ObjDest.Save<br /> End if<br />objDest.CloseDoc 'comment out this line if you'd like dest document to stay open for examination<br />objSource.CloseDoc<br />set objSource=nothing<br />set objDest=nothing<br />set SrcGrp=nothing<br />set SrcProps=nothing<br />set NewGrp=nothing<br />set NewProps=nothing <br />End Sub 'end of Copy_Cycle_Group_Doc_to_Doc-TBhttps://www.blogger.com/profile/08386812862574514289noreply@blogger.comtag:blogger.com,1999:blog-3174073825360154810.post-67125943105822111122013-03-26T01:50:50.483-04:002013-03-26T01:50:50.483-04:00Hi TB,
Thanks for your Valuable post.
This post s...Hi TB,<br /><br />Thanks for your Valuable post.<br />This post save my lot works .perumalhttps://www.blogger.com/profile/13627173824420607929noreply@blogger.com