randlem Posted August 1, 2014 Posted August 1, 2014 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.
Wim Decorte Posted August 1, 2014 Posted August 1, 2014 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)
randlem Posted August 1, 2014 Author Posted August 1, 2014 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¶
Wim Decorte Posted August 1, 2014 Posted August 1, 2014 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.
randlem Posted August 2, 2014 Author Posted August 2, 2014 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.
randlem Posted August 2, 2014 Author Posted August 2, 2014 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,
Wim Decorte Posted August 2, 2014 Posted August 2, 2014 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)
randlem Posted August 2, 2014 Author Posted August 2, 2014 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.
Recommended Posts
This topic is 4020 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now