• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Update VBA to Save File to Location of Current File|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Update VBA to Save File to Location of Current File|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosUpdate VBA to Save File to Location…
sp_PrintTopic sp_TopicIcon
Update VBA to Save File to Location of Current File
Avatar
Sherry Fox
Poinciana, FL
Member
Members
Level 0
Forum Posts: 77
Member Since:
December 4, 2021
sp_UserOfflineSmall Offline
1
April 2, 2022 - 5:58 am
sp_Permalink sp_Print

I have a macro, and it works, however, it does not save the file to the correct folder.  I have this code in my template, and the macro saves a copy for audit purposes.  I would like the macro to save the audit file to the same location as the template is located.  I do not want any hard-coded paths, as this template will be provided to multiple users to have on their computers.  Thanks in advance for your help with this.  I am sure it is something simple, but I have no clue.

 

Sub SaveAudit()

' Save file as multiple cell references

ThisFile = Range("B17").Value & Format(Range("B16").Value, "mm-dd-yyyy") & ".xlsb"
ActiveWorkbook.SaveAs Filename:=ThisFile
End Sub

sp_AnswersTopicSeeAnswer See Answer
Avatar
Jessica Stewart
Northern USA
Member
Members


Trusted Members
Level 0
Forum Posts: 215
Member Since:
February 13, 2021
sp_UserOfflineSmall Offline
2
April 2, 2022 - 3:27 pm
sp_Permalink sp_Print

The path name would be ThisWorkbook.Path, and that will return the path where the file is saved for each computer.

Avatar
Sherry Fox
Poinciana, FL
Member
Members
Level 0
Forum Posts: 77
Member Since:
December 4, 2021
sp_UserOfflineSmall Offline
3
April 6, 2022 - 6:20 am
sp_Permalink sp_Print

@Jessica,

I thought I understood your response, but apparently not.  I revised my code, and when I ran it, I got an error.  Attached is a screenshot of the error, and the location where is showed when I attempted to debug.

Sub SaveAudit()

' Save file as multiple cell references

Dim ThisFile As String
Dim Path As String

ThisFile = Range("B17").Value & Format(Range("B16").Value, "mm-dd-yyyy") & ".xlsb"
Path = ThisWorkbook.Path & "\" & ThisFile

ActiveWorkbook.SaveAs Filename:=ThisFile
End Sub

2022-04-05_16-18-10.jpgImage Enlarger

2022-04-05_16-18-35.jpgImage Enlarger

sp_PlupAttachments Attachments
  • sp_PlupImage 2022-04-05_16-18-10.jpg (12 KB)
  • sp_PlupImage 2022-04-05_16-18-35.jpg (26 KB)
Avatar
Jessica Stewart
Northern USA
Member
Members


Trusted Members
Level 0
Forum Posts: 215
Member Since:
February 13, 2021
sp_UserOfflineSmall Offline
4
April 7, 2022 - 12:49 am
sp_Permalink sp_Print

Your issue is this code right here:

ActiveWorkbook.SaveAs Filename:=ThisFile

I don't work with saving in VBA often, but I believe what you want instead is this:

ActiveWorkbook.SaveAs Filename:=Path

When saving with only the filename you want you haven't given it the path of where to save it.

sp_AnswersTopicAnswer
Answers Post
Avatar
Sherry Fox
Poinciana, FL
Member
Members
Level 0
Forum Posts: 77
Member Since:
December 4, 2021
sp_UserOfflineSmall Offline
5
May 13, 2022 - 12:15 am
sp_Permalink sp_Print

Thanks Jessica,

 

I knew it must have been something very simple. Sorry for my late response.  I was furloughed from my job and just returned this week.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Babak Damadi, Geoff McClure
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 215
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Abisola Ogundele
MARTYN STERRY
Rahim Lakhani
Ngoc Qui Nguyen
Clement Mansfield
Rose .
Bindu Menon
Baruch Zemer
Purple RainbowBenefactor
MOTH Junkie
Forum Stats:
Groups: 3
Forums: 24
Topics: 6350
Posts: 27773

 

Member Stats:
Guest Posters: 49
Members: 32317
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.