PDA

View Full Version : Changeing path where docs are going too. Word 2010



marcdl
11-25-2013, 07:00 AM
Hello people,

I made a word template, a filleble form. But... People have to insert pictures from a certain location in that form (the same dir as where the template is).
When the document gets saved, it should also put it on the same directory.
These directories are on a server.
When I try it, I always get my "standard locations" as I gave them in Word.

I prefer not to use "buttons" in the template, the people who are using it should see immediately the "right" direction, without having to search or even scroll.

Thanks in advance!

Marc

macropod
11-25-2013, 05:18 PM
Does your template use content controls, or formfields? If content controls, see the discussion at: http://www.msofficeforums.com/drawing-graphics/18481-create-content-control-clip-art-not-picture.html#post53751 (http://www.msofficeforums.com/drawing-graphics/18481-create-content-control-clip-art-not-picture.html#post53751). Provided you click on the blue area surrounding the picture icon on the picture content control, and not on the icon itself, the ContentControlOnEnter macro will do its job and open the desired folder. An alternative noted there is to use a Rich Text content control to perform the same function. With a little work, you could even have your own default image/icon in the Rich Text content control.

marcdl
11-26-2013, 12:04 AM
Thanks for the tip, macropod.
However...
The template makes a fillable form, with checkboxes, fields where names has to come. And a field where a portrait of a person is going to be. Its use is intended for a nursinghome: every now and then; some of the (demented) residents leave the premisses. The form is used to fill in some data about the resident, and is stored (with the pictures) on a server. There is only one control "click": when completed, the form is changed into a pdf, and sent through mail to the police and the board.
Since there is no much time to search for the right picture, and some nurses are less computerminded, I would like to set up a code, so that, when you doubleclick the template, you run it (get a new document). Then, automatically, I would like to get it, when they want to insert a picture, they get it immediately to the right folder which contains the pictures of their own floor. And, when they save it, without sending it, it would go to the same folder on the server, not on "my documents" or whatever folder that has become the primary folder for doc's, as noted in Word.
Some doc's are made in advance, since that resident has a known history of "walking away". Those I also place in the folder of that particular ward.

Greetings,
Marc

macropod
11-26-2013, 01:21 AM
The template makes a fillable form, with checkboxes, fields where names has to come. And a field where a portrait of a person is going to be.
If, by that you mean you're using formfields, the fundamental problem you'll have is that pictures can't be inserted into such a document whilst its forms protection (which you need to make it work) is active, so you'll need a macro. The approach taken in the link I posted tells Word where to look for the pictures; but, of course, you'll have to encode the logic for that into the macro.

The form is used to fill in some data about the resident, and is stored (with the pictures) on a server. ... I would like to set up a code, so that, when you doubleclick the template, you run it (get a new document). Then, automatically, I would like to get it, when they want to insert a picture, they get it immediately to the right folder which contains the pictures of their own floor.
And how would the document determine that?

And, when they save it, without sending it, it would go to the same folder on the server, not on "my documents" or whatever folder that has become the primary folder for doc's, as noted in Word.
The choice of folder can be automated, but that requires a macro and, if your users have their Word security options set too high, or they don't allow the macro to run, they'll never get the benefits of the automation code.

marcdl
11-26-2013, 01:49 AM
The form I use does include a field for a picture (don't really know the English name for it...) When clicked on the field, users see their MyPictures path open to choose a picture.

At this moment, I made different paths on the server for every ward. I put shortcuts to this paths on their own pc's. In that path they see their copy of the form (a *.dotm file). In each separate form I'll change the location of the path so that each one goes to the right directory.
Since the pictures of the residents are in the same directory (in a sub-directory), I would like to change that path too.
I want to overrule the default document location.

If the dotm is in directory E: Than the pics are in E:/pics. I want, when they fill in a form, that the reulting .doc comes to E:/docs, and when they want to include the pic, they immediately get the list from E:/ pics.
At this time I get at <code> private sub document_new() </code> to get some code starting when a new doc is made...

Marc

marcdl
11-26-2013, 02:11 AM
Hello forumusers...

I found a way to save the doc in a chosen directory: I use the ChangeFileOpenDirectory "filepath" for it. Now I only need to find a similar code to change the dir for the pictures...

Marc

macropod
11-26-2013, 04:28 AM
You don't need to use ChangeFileOpenDirectory. All you need to do is to specify the path as part of the save parameters. For example:
ActiveDocument.SaveAs2 FileName:="Filepath\Filename.docx", Fileformat:=wdFormatXMLDocument, AddToRecentFiles:=False

The code in the link I posted shows how to change the path where Word looks for a picture.

macropod
11-26-2013, 04:29 PM
Cross-posted, after being given the answers here, at: http://social.msdn.microsoft.com/Forums/office/en-US/e122dc58-0ed6-4908-b195-24dfe5342efe/inserting-pictures-in-a-form?forum=worddev
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

marcdl
11-27-2013, 02:56 AM
Feeling caught with my hands in the cookie-jar...
My apologies for the x-post.

Macropod, the suggested code doesn't seem to work with me. Probably I'm not that good in reading code (a bit a novice...)
Isn't there a more simple solution, that actually points the "insert picture" straight to a fixed directory? So that there is a choise between about 30+ jpg's. And a way that I, in that code, could specify the directory, not the entire path to a jpg?

Thanks!

macropod
11-27-2013, 04:25 AM
In the link, the code line:
Options.DefaultFilePath(Path:=wdPicturesPath) = "C:\Program Files\Microsoft Office\MEDIA\CAGCAT10\"
tells Word where to look for the pictures. For your purposes, simply input whatever other folder's name you want to use.

marcdl
11-27-2013, 05:44 AM
Mr. Edstein,

I think I keep on doing things the wrong way... It won't work on my pc and office.(why is Access so much easier...)

I did copy and change the path like you said, but when I try to click in the blue surrounding field (round the symbol) nothing happens, when I do click on the symbol, yes, I go to the standard location of my pictures.
I tried to change the line with "Clipart" in it to "pictures"...
What if I change it to "if contentcontrol.title <> "" then..."

Or, wouldn't it been easier that I just put a link into the "Favorites folder" when the picturs folder opens?
The link goes to a map on a server, so I used \\srv03\...\...\ (file://\\srv03\...\...\) as my path. Could that do something wrong?

And of course, lots of thanks that you keep helping!

Marc

macropod
11-27-2013, 04:12 PM
Hi Marc,

I'm assuming you are using a picture content control. Is that correct? If so, the code in the link goes in the template's 'ThisDocument' code module. The fact that clicking on the blue outline doesn't trigger the macro suggests you haven't done that.

If you erase the title reference from the code, it will fire for any and every titled content control you enter; I don't expect you really want it to do that.

I suppose you could put a shortcut in the default pictures folder, but that would mean two steps for the insertion of any picture. Even so, it might be useful to have that as a failsafe in case the user clicks on the icon instead of on the blue border (though using a rich text content control would obviate the issue).

marcdl
11-28-2013, 08:58 AM
Hi Paul.

I'm working with on Word in Dutch, so it takes me a little work to translate.
In my Dotm file, all the code goes in the "this document" object, I can see the entire code on the general and document tab.
When I fire the dotm, I have the same code under "project MArc", but under projest, document1 there is nog code at all.
In the beginning of my code, I do use a private sub Document_new. In that one I chage the directory where to put files.

And now, a very stupid question... When I made the Form, I used the tab "Developers" from word itself. With that one, I inserted the place where the picture had to come, in cell of a table. (With help of the control-icons you can see in that tab) In English: Controlelements?
Somewhere I believe that is thing I'm doing wrong...
Would you take a look at the entire code?

I had to change the email and directories, since I could get the reply posted...

Thanks again,

Marc

This is the entire code (with still some testMsgBox in the doc_new routine)


Private Sub CommandButton1_Click()
CommandButton1.Enabled = True
'CommandButton1.Caption = "VERZONDEN"
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Dim docName As String
Dim pdfPath As String


On Error Resume Next
'Controleren of Outlook gestart is
Set appOutlook = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook is niet gestart
Set appOutlook = CreateObject("Outlook.Application")
bStart = True
End If
'Document opslaan
ChDir "//srv03/bewoners"

Set Doc = ActiveDocument
docName = "Vermissingsdocument DOMINO "


'Document opslaan als PDF in de temp map
pdfPath = Environ("temp") & "\"
ActiveDocument.ExportAsFixedFormat _
OutputFileName:=pdfPath & docName & ".pdf", _
ExportFormat:=wdExportFormatPDF
'Nieuw e-mailbericht object maken
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
'Maak een Outlook object en een nieuw mail bericht en verzend deze
Set Outapp = CreateObject("Outlook.Application")
Set Outmail = Outapp.CreateItem(0)
With EmailItem
.Subject = "Vermissing DOMINO"
.Body = "Bijgesloten het ingevulde vermissingsdocument" & vbCrLf & _
"WZC DOMINO VZW" & vbCrLf


.BCC = ""
.CC = my emailadres .To = ""
.Attachments.Add pdfPath & docName & ".pdf"
.Send
End With
'Loop 1 sec om Outlook de kans te geven het e-mailbericht te versturen
s = Timer
Do While Timer < s + 1
DoEvents
Loop
'Opruimen
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
Set Outapp = Nothing
Set Outmail = Nothing

End Sub

Private Sub document_new()

MsgBox "Greetings", vbOKOnly, "Greetings"
ChangeFileOpenDirectory 'Directory where I want to put my docs'

Dialogs(wdDialogFileOpen).Show
End Sub

Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Dim StrPath As String
If ContentControl.Title = "ClipArt" Then
With Application.Dialogs(wdDialogInsertPicture)
StrPath = Options.DefaultFilePath(Path:=wdPicturesPath)
Options.DefaultFilePath(Path:=wdPicturesPath) = ' The place where I want to find my Picture'
.Update
If .Show = True Then
With ContentControl.Range
If .InlineShapes.Count > 1 Then .InlineShapes(1).Delete
End With
End If
Options.DefaultFilePath(Path:=wdPicturesPath) = StrPath
End With
End If

End Sub

macropod
11-28-2013, 02:04 PM
Hi Marc,

When you put code into a document's template, that makes the code available to the document, without it having to be in the document itself. That explains why there's no code in the new documents.

With the code you've posted, the 'CommandButton1_Click' sub belongs in a userform, but the 'document_new' sub and the 'Document_ContentControlOnEnter' sub both belong in the 'ThisDocument' module. In the 'Document_ContentControlOnEnter' sub, you have the line:
Options.DefaultFilePath(Path:=wdPicturesPath) = ' The place where I want to find my Picture'
That won't work, as you're not telling Word where to look. You should be able to use something like:
Options.DefaultFilePath(Path:=wdPicturesPath) = \\srv03\bewoners\
At worst, you might need to use the server's drive name instead of its server name (e.g. H:\bewoners\).

marcdl
11-29-2013, 01:51 AM
Thank you Paul.

I did change the "Options.DefaultFilePath(Path:=wdPicturesPath) = ' The place where I want to find my Picture' " for posting only.
When I did put the real name in it, I got an error from this forum, I used too many links.
Maybe my WORD version is not complete... From the beginning I keep having the same problem with the picture to insert. When I hoover the mouse over the blue field, the cursos changes in the crossed arrows mode, like a select. I can't click then. I can only click on the icon of the "picture to insert", and that one directs me to the default location. And, oddly, when I manually change the default filepath of the pictures folder, I keeps directing me to the "my pictures" folder.Looks I got a very stubborn 2010 version of word.


Greetings from Marc;

macropod
11-29-2013, 03:00 AM
Can you attach a document to a post with the content controls and your current macro(s) - delete anything sensitive? You do this via the paperclip symbol on the 'Go Advanced' tab.