Kevin Mortimer Posted July 7, 2006 Posted July 7, 2006 I have the start of some VBS that opens a word doc. I then want to somehow grab the contents of the document and insert the contents into field in my database. Is this possible? I also want to call on a FMP script at the end of the VBS if possible. Here is my VBS so far.......I hope it makes sense. Set objWord = CreateObject("Word.Application") objword.Visible = False Set objDoc = objWord.Documents.Open("192.168.0.50adminHRSCvsDaxtraCVs14123819122005_4622_original.doc") [color:red]I need Help here objWord.Quit [color:red]I need Help here objFMfiles.DoFMScript ("test1")
Wim Decorte Posted July 8, 2006 Posted July 8, 2006 You weren't kidding when you said you the "start" of the VBscript Check out the "Content" property of the Word document object. You'll find it in the Word VBA help file. To get it back into FM, you'll need to have the VBscript write the content out to a text file on the hard disk (checkout "scripting.filesystemobject"), and then call a FM script that imports that same text file. The FM script also needs to clean up: delete the VBscript and the intermediate text file from the drive. Check out the ActiveX section in the FM help on how to write the code to call a FM script. Or check out the "Solutions" forum, I've posted a full example a couple of months ago. That example grabs the list of files from a folder so it does not show the Word part, but it does demo the creation of an intermediate text file and the import. You can avoid having to create the VBscript and intermediate file on the hard disk by using the VBscript plugin from www.grokittools.com. The VBscript plugin returns the result directly to a field without having to import.
aholtzapfel Posted July 26, 2006 Posted July 26, 2006 Check out the Object model for Internet Explorer. You can use it to access the clipboard from a script and then have a FM script paste it into a field. You do not have to show an IE window to do this and avoids having to import anything. Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_") oIE.Visible = 0 oIE.document.parentwindow.clipboardData.SetData("text"),( Whatever you want on the clipboard ) WScript.DisconnectObject(oIE)
Wim Decorte Posted July 27, 2006 Posted July 27, 2006 Yep, but destroying what the user may have on the clipboard is considered bad form, and should be avoided wherever possible. Works though...
Raybaudi Posted July 27, 2006 Posted July 27, 2006 So this may be the VBScript: Set objDialog = CreateObject("UserAccounts.CommonDialog") objDialog.Filter = "FileMaker Files|*.fp7|All Files|*.*" objDialog.FilterIndex = 2 objDialog.InitialDir = "C:" intResult = objDialog.ShowOpen If intResult = 0 Then Wscript.Quit Else Set oIE = WScript.CreateObject("InternetExplorer.Application", "IE_") oIE.Visible = 0 oIE.document.parentwindow.clipboardData.SetData("text"),objDialog.FileName Wscript.DisconnectObject(oIE) End If ...but there must be an error somewere, and I don't know much of VBScipt. Can you correct the error ?
Wim Decorte Posted July 27, 2006 Posted July 27, 2006 You're missing a lot of code in there. After the user selected a file, you need to talk to word, have it open the file (invisibly) and grab all the content, put it on the clipboard then finally call a FM script to paste it into the correct FM field. I'm still not a big fan of using the clipboard to do this though.
Raybaudi Posted July 27, 2006 Posted July 27, 2006 (edited) Thank you Wim. I said that I don't know VBScript. But I think that i'm missing NOT a lot of code... as I haven't to talk with Word, neither to open the file... I just need to grab the NAME of the file ( objDialog.FileName )and paste it into the clipboard. So, my [color:blue]real question is: given this code: [color:blue]Set objDialog = CreateObject("UserAccounts.CommonDialog") objDialog.Filter = "FileMaker Files|*.fp7|All Files|*.*" objDialog.FilterIndex = 2 objDialog.InitialDir = "C:" intResult = objDialog.ShowOpen If intResult = 0 Then Wscript.Quit Else [color:red]XXXXXXXXXXXXXXXXXXXXXX [color:blue]End If which code I have to write where now there is [color:red]XXXXXXXXXXXXXXXXXXXXXX to paste objDialog.FileName into the clipboard ?? Edited July 27, 2006 by Guest
Wim Decorte Posted July 28, 2006 Posted July 28, 2006 Daniele, the topic of this thread was how to grab the [color:purple]contents of a document, not how to grab the name of a chosen file. Here's your modified VBscript. One of the rules in VBscript is that you don't use parenthesis around the arguments of a function if you're using that function as a standalone call. oIE.document.parentwindow.clipboardData.SetData "text", chosenFile but something = oIE.document.parentwindow.clipboardData.SetData ("text", chosenFile) Set objDialog = CreateObject("UserAccounts.CommonDialog") objDialog.Filter = "FileMaker Files|*.fp7|All Files|*.*" objDialog.FilterIndex = 2 objDialog.InitialDir = "C:" intResult = objDialog.ShowOpen If intResult = 0 Then Set objDialog = Nothing WScript.Quit Else chosenFile = CStr(objDialog.FileName) MsgBox objDialog.FileName Set oIE = WScript.CreateObject("InternetExplorer.Application") oIE.Visible = 0 oIE.Navigate("about:blank") oIE.document.parentwindow.clipboardData.SetData "text", chosenFile oIE.Quit Set oIE = Nothing Set objDialog = Nothing End If
Wim Decorte Posted July 28, 2006 Posted July 28, 2006 Here's a link to a demo file I posted a while back that shows how to do the import approach instead of using the clipboard. It grabs all the file names of a chosen folder instead of one chosen file, but you can change the VBscript easily. http://www.fmforums.com/forum/showtopic.php?tid/173921/post/193806/hl//
Raybaudi Posted July 28, 2006 Posted July 28, 2006 "Daniele, the topic of this thread was how to grab the contents of a document, not how to grab the name of a chosen file." Yes, Wim, you are right... I realized that only some times later, so I edited my post. But I'm here to give you all my best THANKS for your kind words and for your perfect code !! I had just read ALL your previous post about VBscript but didn't find something alike this code to place something into the clipboard. Again thank you very much.
Raybaudi Posted July 28, 2006 Posted July 28, 2006 Now, Win, I wish to know how to modify that code so that: 1) FM 8.5 2) WebViever pointing to a local .vbs file 3) the .vbs file makes something alike the previous code, but place the result (the fileName) directly into the WebViever ( and not into the clipboard ) If it's possible, after I'll retrive that information with the new function: GetLayoutObjectAttribute ( )
Wim Decorte Posted July 29, 2006 Posted July 29, 2006 (edited) The web viewer can't execute a VBscript. But you're on the right track. See attached file. The VBscript chooses a file, and writes out a very small HTML page with the filename. The VBscript then triggers a script in FM that scrapes the contents of the web viewer (the web viewer is set up to display the content of that HTML page that the VBscript generates). Everything is self contained inside the FM file. Let me know if something is not clear... ReturningResultThroughWebViewer.zip Edited July 29, 2006 by Guest file didn't upload
Raybaudi Posted July 29, 2006 Posted July 29, 2006 Many thanks, Wim. It is exactly what i was looking for !! Now a question: Can I learn ALL about VBscript from script56.chm alone ? Or I have to look at other resources ? BTW: I have stripped the ScrapeResult script to only 6 step...and modified your "Main" layout to contain a WebViever of 1x1 pixel; if you wish I can post it. The web viewer can't execute a VBscript. Are You sure ? For example this works (...but I don't know if it can be considered a VBscript) "about: MsgBox"touche !", 0, "Attenction" " And, while we are here, do you think that FM can react to that event ?
Wim Decorte Posted July 31, 2006 Posted July 31, 2006 Technically it's not the web viewer executing the vbscript, it is run by IE. Problem with that is that it depends on the IE security settings so you may not have full control over that. I thought you meant pointing the Web Viewer directly to an .vbs file on the hard disk. No, FM can't react to that event. A good vbscript resource is www.microsoft.com/scripting.
Brudderman Posted July 31, 2006 Posted July 31, 2006 The VBscript chooses a file, and writes out a very small HTML page with the filename. The VBscript then triggers a script in FM that scrapes the contents of the web viewer (the web viewer is set up to display the content of that HTML page that the VBscript generates). Thanks for showing how to do this, Wim. Is there any way to take just the dialog box part of your vbs code and return a selected file name to FM without going through the web viewer? Or is this the most efficient way? I'm recalling a previous example of yours where you browsed for a folder and brought back a list of all of the files there. Thanks!
Wim Decorte Posted August 1, 2006 Posted August 1, 2006 Hi James, There are basically 4 ways of getting the result from a VBscript back into FM: - pasting (Ugh ) - importing (that was in the example you're alluding to) - the web viewer - using the vbscript plugin (www.grokittools.com) If FM fixes the ActiveX model to allow us to pass a parameter to a script then that would be the most efficient way. You can of course exchange data with FM through Server Advanced too.
Brudderman Posted August 1, 2006 Posted August 1, 2006 Thanks, Wim. It would be nice to pass a parameter, wouldn't it? Maybe next time. I'll compare your example grabs a list of files from a folder with the web viewer one and pick a course of action. James
Kevin Mortimer Posted August 28, 2006 Author Posted August 28, 2006 I had a look at your file that outputs the selected file name to an HTMl file. Then you can grab the contents of the html file from the web viewer. I would like to do a similar thing except output the contents of a word doc to an html file which can be read by the web viewer. Would this be possible to do without bringing all the gobly gook (formating) that comes with the word document.
Wim Decorte Posted August 28, 2006 Posted August 28, 2006 Sure. You'd need the VBscript to grab the plain text content of a Word document and then write it out to a text file. The web viewer will display the text file and you can grab it from there. The URL for the web viewer would be something like: file:///C:/test.txt
Recommended Posts
This topic is 6705 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