August 1, 201411 yr Afternoon Guys, I could do with some help with following code: Set objFM = WScript.CreateObject ('FMPRO.Application')¶ If objFM.ScriptStatus = 0 then¶ Set objFMfiles = objFM.Documents.Open(‘Database.fmp12','un','pw')¶ objFM.Visible = True¶ objFMfiles.DoFMScript ('OpenQuotationScript')¶ End If¶ This code basically opens a word doc after it has had it's bookmarks populated and closed. The code works fine until a different user other than the one I used in the 'un' & 'pw' is logged in and then I get a WSH error. So is there a way of using the Set objFMfiles = objFM.Documents.Open(‘Database.fmp12','un','pw') without needing to use a username & password or somehow getting the Users username & password. I have tried using GetObject instead of Open but with no success. Any pointers would be most appreciated. Kind regards, Mark.
August 1, 201411 yr if FM is already running and the file open, then you don't need to issue the Open command, just loop through the FM documents collection until you have the right one targeted and then run the script Set objFMfiles = objFM.Documents is the collection (all open FM files)
August 1, 201411 yr Author if FM is already running and the file open, then you don't need to issue the Open command, just loop through the FM documents collection until you have the right one targeted and then run the script Set objFMfiles = objFM.Documents is the collection (all open FM files) Hi Wim, Thanks for your response. Not too sure what you mean by "just loop through the FM documents collection until you have the right one targeted and then run the script" So is the code below what I should be looking at?. Set objFM = WScript.CreateObject ('FMPRO.Application')¶ If objFM.ScriptStatus = 0 then¶ Set objFMfiles = objFM.Documents.DoFMScript ('OpenQuotationScript')¶ objFM.Visible = True¶ End If¶
August 1, 201411 yr No, something like this: (I'm not on a Windows machine right so I can't check for syntax errors) Set objFMfiles = objFM.Documents for each objTargetFile in objFMfiles if objTargetFile.fullname = "Database" then objTargetFile.DoFMScript ('OpenQuotationScript') end if next Ideally you would shortcut the loop if you have found your target file obviously, no point in continuing the loop. You also should clean up your objects and set them to nothing when you are done.
August 2, 201411 yr Author No, something like this: (I'm not on a Windows machine right so I can't check for syntax errors) Set objFMfiles = objFM.Documents for each objTargetFile in objFMfiles if objTargetFile.fullname = "Database" then objTargetFile.DoFMScript ('OpenQuotationScript') end if next Ideally you would shortcut the loop if you have found your target file obviously, no point in continuing the loop. You also should clean up your objects and set them to nothing when you are done. Hi Wim, Thanks for that. I tried the following code: Set objFMfiles = objFM.Documents¶ for each objTargetFile in objFMfiles¶ if objTargetFile.fullname = 'D&H Sales Database - Development.fmp12' then¶ objTargetFile.DoFMScript ('OpenAcknowledgementScript')¶ end if¶ next¶ Set objFMfiles = nothing¶ Set objFM = nothing¶ Set objTargetFile = nothing¶" I got a WSH error - Object Required 'objFM' Then I tried (with & without the .fmp12): Set objFM = WScript.CreateObject ('FMPRO.Application')¶ Set objFMfiles = objFM.Documents¶ for each objTargetFile in objFMfiles¶ if objTargetFile.fullname = 'D&H Sales Database - Development.fmp12' then¶ objTargetFile.DoFMScript ('OpenAcknowledgementScript')¶ end if¶ next¶ Set objFMfiles = nothing¶ Set objFM = nothing¶ Set objTargetFile = nothing¶" The error go but the objTargetFile.DoFMScript ('OpenAcknowledgementScript')¶ does not fire. Kind regards, Mark.
August 2, 201411 yr Author No, something like this: (I'm not on a Windows machine right so I can't check for syntax errors) Set objFMfiles = objFM.Documents for each objTargetFile in objFMfiles if objTargetFile.fullname = "Database" then objTargetFile.DoFMScript ('OpenQuotationScript') end if next Ideally you would shortcut the loop if you have found your target file obviously, no point in continuing the loop. You also should clean up your objects and set them to nothing when you are done. Hi Wim, I found some code on a google search that I had not spotted which works: Set FMApp = CreateObject('FMPRO.Application')¶ Set FMDocs = FMApp.Documents¶ FMApp.Visible = True¶ Set FMActiveDoc = FMDocs.Active¶ FMActiveDoc.DoFMScript ('OpenAcknowledgementScript')¶ Set FMDocs = Nothing¶ Set FMActiveDoc = Nothing¶" Many thanks for all you help. Kind regards,
August 2, 201411 yr Set objFMfiles = objFM.Documents¶ for each objTargetFile in objFMfiles¶ if objTargetFile.fullname = 'D&H Sales Database - Development.fmp12' then¶ objTargetFile.DoFMScript ('OpenAcknowledgementScript')¶ end if¶ next¶ Set objFMfiles = nothing¶ Set objFM = nothing¶ Set objTargetFile = nothing¶" I got a WSH error - Object Required 'objFM' If this all the code you were using then you have not set or declared an "objFM" in your code, so you can't call it (1st line)
August 2, 201411 yr Author If this all the code you were using then you have not set or declared an "objFM" in your code, so you can't call it (1st line) Hi, I did set/declare 'objFM': Set objFM = WScript.CreateObject ('FMPRO.Application')¶ Set objFMfiles = objFM.Documents¶ for each objTargetFile in objFMfiles¶ if objTargetFile.fullname = 'D&H Sales Database - Development.fmp12' then¶ objTargetFile.DoFMScript ('OpenAcknowledgementScript')¶ end if¶ next¶ Set objFMfiles = nothing¶ Set objFM = nothing¶ Set objTargetFile = nothing¶" But the script did not fire. Regards, Mark.
Create an account or sign in to comment