Change document properties, embedded feature.

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
McFrede
Newbie
Posts: 10
Joined: Fri Dec 03, 2004 2:24 pm
Location: Denmark
Contact:

Change document properties, embedded feature.

Post by McFrede » Thu Apr 21, 2005 8:53 am

As I sometimes have a template document get values from the document's properties (revision level, material, colour etc.) it would be nice to be able to manipulate these directly from Macro Scheduler.
I know I could make some keystrokes and "send chars", but a more direct approach to this would help a lot.

Example:
I have designed a component, and made an ini-file that contains kay data about the project, such as "project number", "material", "colour" and a lot of other information that will be needed in several of the project documents, such as the drawing and the quote for the customer etc.
I would like an easy way of getting the data from the ini-file to the custom properties tab of a named file.
This way I would be able to automate a lot of writing in each project, since data that are already known can be filled in from the template file and thus I would only have to fill in the document-specific text.

Got it?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Apr 21, 2005 1:28 pm

Rough outline:
--------------------------------------------------
SetFocus>WindowName*

Put the following into a loop and do for each document property:

ReadIniFile>inifile,section,entry,result
Tab to data entry position
Send>%Result%
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

McFrede
Newbie
Posts: 10
Joined: Fri Dec 03, 2004 2:24 pm
Location: Denmark
Contact:

OK, I'll explain...

Post by McFrede » Thu Jun 16, 2005 7:15 am

I just posted it as a suggestion in the bugtracker here:

http://www.mjtnet.com/bugtracker/bug.ph ... w&bugid=38

I wrote this to explain, and if you read the links (shouldn't take too long), I hope you will also get the idea why this could be a powerful tool:

"
Just read a bit about something called DSOfile
http://blogs.msdn.com/gstemp/archive/20 ... 79867.aspx
and thought it might be exactly what I need, however I am not that hardcore at VB scripting. The beauty of this is that you would not have to make a keystroke-macro in order to manipulate custom properties. As my vision is to have documents in my company autofilled from a .ini-file (thank you MacroScheduler), this would be just that little extra i need to get on with the project.
Also, you may find more here:
http://support.microsoft.com/kb/q224351/
"

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Jun 16, 2005 7:28 am

What sort of "documents" are you talking about!? It might hellp if we knew what application you are referring to. Are you talking about Microsoft Word? If so you can probably already do what you want using VBScript.
MJT Net Support
[email protected]

McFrede
Newbie
Posts: 10
Joined: Fri Dec 03, 2004 2:24 pm
Location: Denmark
Contact:

Getting to the bone...

Post by McFrede » Thu Jun 16, 2005 8:07 am

Hi there,

No not only Word, but also Excel and SolidWorks files (3D CAD program).
It might just be me, but I have found that the risk of messing up greatly increases when using keystroke macros. Therefore, it would be helpful if you could point out a file and manipulate the data directly.

The reason for all this? Well I am working in a medium-sized company in the development department, and often when dealing with the automotive business, the documentation takes forever to finalize, and often one may use standard documents. This leads to me having to duplicate data from one document to another. I have found a way to get word to fill in text from its custom properties into the document. I can also store this generic data in a .ini-file (project number, partnumbers, part weight, prices etc.). What I need is a convenient way to read and write data to the custom properties of a file.

Let us say for example that I have done a calculation for a product, and now I have to make a final quote, I will have to duplicate part number, project number, material type, price... from the calculation into the quote. Instead I would like to read the custom properties from the calculation and put them into the custom properties of the quote. This way all I would have to do would be to open the quote template, update it and all that would be left would be to fill in the document-specific data.

I can explain further if I am unclear on some points.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Jun 16, 2005 8:23 am

Word and Excel (and other Office) documents can already be manipulated directly by Macro Scheduler using VBScript. No need for keystrokes. Excel sheets can also be manipulated directly via DDE. There are several examples of Excel automation using DDE and VBScript on this site. I know nothing about SolidWorks but if it has an ActiveX interface like MS Office does then it could also be manipulated directly.

Any application that provides a scripting interface (such as ActiveX) can be manipulated within the limitations of that scripting interface without need for mouse/key simulation. But those that don't (the majority) nearly always need some form of user simulation using key strokes / mouse events. That is why Macro Scheduler exists. If all applications let you script them directly we would never have had to develop Macro Scheduler in the first place. VBScript was added to Macro Scheduler primarily to provide for applications that do provide an ActiveX scripting interface.

The following simple example opens Word, opens up a new document based on the Normal template and writes out the text Hello World:

VBSTART
Sub WordExample
Set WDOC = CreateObject("Word.Application")
WDOC.visible = true
WDOC.Documents.Add "Normal.dot", False, 0
WDOC.Selection.TypeText "Hello World"
End Sub
VBEND
VBRun>WordExample

No keystrokes! This is just the tip of the iceberg with what is possible. There are lots of examples in this forum of using Excel in a similar way:

http://www.mjtnet.com/forum/viewtopic.php?t=1464
http://www.mjtnet.com/forum/viewtopic.php?t=1470
http://www.mjtnet.com/forum/viewtopic.php?t=1482
MJT Net Support
[email protected]

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

VBScripting Office Tip

Post by support » Thu Jun 16, 2005 8:28 am

A tip for writing VBScript code to automate Office apps:

First create the Office application object:

Set WDOC = CreateObject("Word.Application")or
Set XL = CreateObject("Excel.Application")

To figure out the code go to Word/Excel and record a native VBA macro to do what you want. To determine the Word example above I first recorded opening a new document. The VBA code looked like this:

Documents.Add Template:= _
"Normal.dot" _
, NewTemplate:=False, DocumentType:=0

VBA lets you put the parameter name := value in each parameter. You can't do this with VBScript, but just removing the parameter name part and making sure the values are in the correct order is all you need to do. So the VBScript becomes:

WDOC.Documents.Add "Normal.dot", False, 0

Obviously I have added the command to the end of WDOC which is the Word Document Object I created with the CreateObject call.
MJT Net Support
[email protected]

McFrede
Newbie
Posts: 10
Joined: Fri Dec 03, 2004 2:24 pm
Location: Denmark
Contact:

Manipulating the files directly vs. changing their propertie

Post by McFrede » Mon Jun 20, 2005 12:03 pm

I will try and see how far I can come manipulating the files directly, namely excel, and see where that may bring me. For non excel files though I still haven't gotten a clear idea of how to manipulate their custom properties directly. I will investigate further...

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts