Creating file from a template file on OneDrive

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,600
Office Version
  1. 365
Platform
  1. Windows
I have a file on OnDrive which is a template financial reporting tool.

I use the following code to create an annual file from the template
VBA Code:
Sub NewFile()

If Range("FD_FileType") = "Template" Then
   Else
   MsgBox ("This file is not the Template file and cannot be used to set up a new file"), vbExclamation, "ERROR"
   
   Exit Sub
End If

boolCancel = False

Load frmYear

frmYear.Show

Unload frmYear

If boolCancel = True Then
   Exit Sub
   Else
End If

Range("FD_FileType") = ""
Range("FD_Year") = strYear

Range("LYTB_Clear").ClearContents
Range("CYTB_Clear").ClearContents

strPath = ActiveWorkbook.Path
strPath = Replace(strPath, "https://d.docs.live.net/037c9df14c70d425/", "C:\Users\User\OneDrive\")
strPath = Replace(strPath, "/", "\")

Set objFSO = CreateObject("scripting.filesystemobject")

If objFSO.folderexists(strPath & "\" & strYear) = True Then
   Else
   objFSO.createfolder (strPath & "\" & strYear)
End If

Set objFSO = Nothing

With ActiveSheet
   .Unprotect Password:=strPassword

   .Shapes("shpCreate").Fill.ForeColor.RGB = RGB(226, 240, 217)
   .Shapes("shpCreate").TextFrame.Characters.Text = "BUTTON DISABLED - ANNUAL FILE CREATED"
   .Shapes("shpCreate").TextFrame.Characters.Font.Size = 12
   
   .Protect Password:=strPassword
End With

ActiveWorkbook.SaveAs strPath & "\" & strYear & "\Financial Reporting " & strYear & ".xlsm"

MsgBox ("This file has been saved as the selected year file"), vbInformation, "FILE SAVED"

End Sub
This sucessfully creates the annual file but where the following ranges are cleared as part of setting up the new file, these are being saved to the Tam,plate file despite there being not code save the Template file other than as the annual file.
Range("FD_FileType")
Range("FD_Year")

Can anyone shed some light on this as the file is for a client and we're both finding it frustrating that Excel is not doing as it is told.


TIA
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top