Change file name

D

dsc

I actually have two bonehead questions, one of which I think has been
answered here a couple of years ago.

I want to do a macro that lets the user change the name of both the active
file and a file of the same name in a different directory, without closing
the file.

It occurs to me that I can probably use FileSaveAs and then kill the
unneeded files, but is there a better way to do it? I couldn't find a
function in VBA help.

I am also getting some undesired effects when a user form is closed using
the little X at the top right instead of the CloseButton. Could somebody
tell me how that's dealt with?

Thanks very much for any assistance.
 
A

Anand.V.V.N

Hi dsc,
I want to do a macro that lets the user change the name of both the active
file and a file of the same name in a different directory, without closing
the file. It occurs to me that I can probably use FileSaveAs and then kill the
unneeded files, but is there a better way to do it? I couldn't find a
function in VBA help.

Renaming a file in use is not possible becuse the OS won't allow. Is that
what you mean by active I suppose. What you can do is close the file rename
it and open it again.
I am also getting some undesired effects when a user form is closed using
the little X at the top right instead of the CloseButton. Could somebody
tell me how that's dealt with?
By the do you have a close button in which you calling some code?

Anand
 
J

JBNewsGroup

Hi Anand,

In the form's QueryClose do the following:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode <> 1 Then Cancel = 1
End Sub

The "Red X" is effectively disabled and when the user clicks on it nothing
happens. This allows you to use your
CloseButton to clean up on exit.

Jerry Bodoff
 
P

Perry

'Renaming active:
Dim sOrgName As String
Dim sNewName As String
Dim sOtherPath As String

sOtherPath = "Y:\MyOtherPath"
sOrgName = ActiveDocument.Name
sNewName = "MyNewDoc.doc"
ActiveDocument.SaveAs ActiveDocument.Path & "\" & sNewName
Kill ActiveDocument.Path & "\" & sOrgName

'ReName other file (note: one liner)
Name sOtherPath & "\" & sOrgName As _
sOtherPath & "\" & sNewName

'Disable X-button
Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)

Cancel = CloseMode = 0
End Sub

-------------------------------------
Krgrds.
Perry

System parameters:
POS: WinXP x64
MSO: MSOffice System
DEV: VS7 (dotnet)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top