PDA

View Full Version : Setting default name in Save As dialog



mrzeus7
08-06-2014, 08:34 PM
I'm trying to set a default save-as name (it uses punctuation like ',' and '-', so setting the Title in doc properties won't work) and spent a sizable chunk of my day at work trying to fix a problem I've had, only to go home and try it on my home computer and have it work.

I use this code in one of my modules:

Sub saveDialog()
Dim dlg As dialog

Dim pStr As String
pStr = getDocTitle
Set dlg = Application.Dialogs(wdDialogFileSaveAs)
With dlg
.Name = potcpath & pStr
.show
End With
End Sub


Sub FileSave()
saveDialog
end sub

It is supposed to have the save-as file name in the save-as dialog box set to what getDocTitle returns (a string) (potcpath is declared in an init function). It does exactly this on my home computer, but on my computer at work it uses the normal default file name (the Title of the document, or the first couple words, etc.). I'm not sure why. I started thinking (after I left work, of course) I thought it may be because the default path is a networked path, while my computer doesn't have that. I'll test in the morning, but if that is the case, is there a way to get around it? Pretty much all of our things are saved on the network there.

Any other ideas about what could be happening?

macropod
08-06-2014, 11:59 PM
You will need to check the validity of what potcpath & pStr hold. For example, before calling the dialogue:
MsgBox potcpath & pStr

mrzeus7
08-07-2014, 07:27 AM
I checked by hard-coding it there to an address on the hard drive (not the network) on my work computer, still doesn't work. I also tried something that I think has interesting results:



Set dlg = Application.Dialogs(wdDialogFileSaveAs)
With dlg
.Name = potcpath & pStr
MsgBox .Name
.show
MsgBox .Name
End With

Both message boxes show the desired path...but whats in the "file name" field in the save-as dialog box is different.

macropod
08-07-2014, 03:30 PM
Merely saying they are different doesn't help resolve the issue. In what way are they different?

mrzeus7
08-07-2014, 04:01 PM
From my original post:


It does exactly this on my home computer, but on my computer at work it uses the normal default file name (the Title of the document, or the first couple words, etc.). I'm not sure why.

macropod
08-07-2014, 04:14 PM
Meaningless.

mrzeus7
08-08-2014, 07:16 AM
On my work computer: When I have a title set, it uses that (but stops at punctuation). When I don't have a title set, it uses the first couple words in the document.

On my home computer: the name/path is set to whatever I set it as in VBA (this is what I want)

I don't know how else I can say it.

macropod
08-08-2014, 03:56 PM
That suggests whatever you have in 'potcpath & pStr' on the work computer is invalid.

mrzeus7
08-09-2014, 05:35 PM
I agree that's a possibility, and I'll check that out on Monday. I have copied the path from Windows Explorer (a path to a location on our network) and put it in potcpath (Something like "K:/path"), though I've also seen that same path as something like "//Servername/path". I can't say for sure what they each started with, but I'll check both ways when I get back.

However, I'm skeptical of that being the problem. When I'm on my home computer, it works when I specify ONLY the file name. Usually I test with pStr = "TestName.docx", and I don't concatenate it to potcpath (So that line would be ".name = "TestName.docx""). On my home computer, this works perfectly (though it isn't in the default path, it only has the TestName.docx I specified). I have also done this same thing on my work computer, where it didn't work (see post #7). So I've done the exact same thing, on both computers where one worked and the other didn't.

Given this information, can we assume for the weekend (until I can test it) that the path is NOT the problem?

macropod
08-09-2014, 08:53 PM
Given this information, can we assume for the weekend (until I can test it) that the path is NOT the problem?
I wouldn't be willing to make that assumption. I'd want to verify it...

mrzeus7
08-14-2014, 04:42 PM
Ok, I've finally had some time to give this a shot. I put in "C:\Users\myusername\Desktop\" as "potcpath", and "TestName.docx" as pstr. My msgbox's in the code confirms this is C:\Users\myusername\Desktop\TestName.docx in .name (msgbox .name). But it still doesn't show it. I used the nearly the same potcpath (changed my username appropriately) at home last night, and it showed that path and filename as the default save path/name, so it does not seem like that is the problem.

macropod
08-14-2014, 05:06 PM
That suggests "C:\Users\myusername\Desktop\" is not a valid path on your work system.