Creating a Document in same folder when another document is opened

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
OK So heres what I need,
I need two macros,
1 when the document is opened it creates a new document in the same folder called "Used"
When the document is closed it deletes the docment called "Used"

how can I do this.

Thanks

Tony
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
place code in ThisWorkbook module
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    DeleteUsed
End Sub

Private Sub Workbook_Open()
    DeleteUsed
    CreateUsed
End Sub

Private Sub DeleteUsed()
    On Error Resume Next
    Kill ThisWorkbook.Path & "\Used.xlsx"
End Sub

Private Sub CreateUsed()
    Application.ScreenUpdating = False
    Dim wb As Workbook
    Set wb = Workbooks.Add
    Application.DisplayAlerts = False
    wb.SaveAs Filename:=ThisWorkbook.Path & "\Used.xlsx"
    Application.DisplayAlerts = True
    wb.Close False
End Sub

:warning: VBA will not do what you require if placed in incorrect module
 
Last edited:
Upvote 0
1 when the document is opened it creates a new document in the same folder called "Used"
When the document is closed it deletes the docment called "Used"
Word uses documents, Excel uses workbooks. To avoid confusion, please use the standard MS Office terminology.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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