PDA

View Full Version : [SOLVED:] Copy Normal.dotm file



dzogchen
05-10-2021, 02:02 AM
Good Morning!

I'm trying to make an auto Normal.dotm copy file routine when I open a excel file because sometimes i lost my saved macros. Since the file Normal.dotm has all the macros saved seems to me a good idea to save it from time to time.


The code is the follwing



Private Sub Workbook_open()
Dim a As Integer


a = Range("A1").Value + 1


Range("A1").Value = a


FileCopy "C:\Users\njesus\AppData\Roaming\Microsoft\Templates\Normal.dotm", "C:\Users\njesus\Dropbox\Setcontrol\VBA\Normal" & Range("A1").Value & ".dotm", strDBLocation


End Sub




When the macro runs i'm getting the error:

"Compile error

Wrong number of arguments or invalid property assignment"


maybe because of the Windows folder properties.

Also i don't have Administrator rights because it is my work desktop

Is there a better way to solve it?

Regards

snb
05-10-2021, 02:16 AM
In Normaltemplate Document macromodule:


Sub Autoexit()
c00 = Options.defaultfilepath(5) + "\"
c01 = Format(NormalTemplate.builtindocumentproperties(12), "yyyy-mm-dd")

If Dir(c00 & c01 & "*") = "" Then
Documents.Open NormalTemplate.FullName
ActiveDocument.SaveAs c00 & c01 & "_normal.dotm"
ActiveDocument.Close
End If
End Sub

macropod
05-10-2021, 03:07 AM
I'm trying to make an auto Normal.dotm copy file routine when I open a excel file because sometimes i lost my saved macros.
Why would you want to make a copy of Word's Normal.dotm file when you open and Excel workbook? Makes no sense to me.

Moreover, if you aren't making backups using the tools that come with Windows, why not?

SamT
05-10-2021, 05:12 AM
I don't know about Normal.dotm, but I SaveCopyAs Excel's Personal.* every time I edit it, then use Windows to backup that entire folder weekly

In Excel's Personal THisWorkbook Code page
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not Me.Saved Then ThisWorkbook.Save
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As Boolean)
Me.SaveCopyAs ("D:\!Backup\_Personal\Personal - " & CStr(CDbl(Now)) & ".xls")
End Sub

CStr(CDbl(Now)) just adds a timestamp so I can Save often without overwriting previous versions.

Kenneth Hobs
05-10-2021, 07:07 AM
'FileCopy "C:\Users\njesus\AppData\Roaming\Microsoft\Templates\Normal.dotm", "C:\Users\njesus\Dropbox\Setcontrol\VBA\Normal" & Range("A1").Value & ".dotm", strDBLocation

FileCopy "C:\Users\njesus\AppData\Roaming\Microsoft\Templates\Normal.dotm", "C:\Users\njesus\Dropbox\Setcontrol\VBA\Normal" & a & ".dotm"

dzogchen
05-10-2021, 07:14 AM
Afternoon!

@snb: I tested your code and it worked on microsoft word. Thank you!

@macropod: I'm trying to copy the file in excel because i have always one excel spreadsheet open and since i have one routine to make periodicly backus from time to time in that spreadsheet i could use that routine also to copy the Normal.dotm file. At the beginning i must confess that i thought to copy Normal.dotm file was straight away. Using backups tools that come with Windows could be a solution also, i didn't remember that, thank you!

@SamT: i will test your code, give me 1h or 2h. Thank you!

Regards

dzogchen
05-11-2021, 09:02 AM
Afternoon,

@Kenneth Hobs: That is what I was looking for!!! Thank you very much!!!!

@SamT: Thank you for your reply!

dzogchen
05-11-2021, 09:23 AM
Afternoon again,

I can say now for those who may interest that for this code works:


FileCopy "C:\Users\njesus\AppData\Roaming\Microsoft\Templates\Normal.dotm", "C:\Users\njesus\Dropbox\Setcontrol\VBA\Normal" & Sheets("Folha2").Range("F2").Value & ".dotm"


you need to change the Windows folder securety properties

Regards