Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2017, 02:22 AM
Cyberseeker Cyberseeker is offline Edit Filename Path? Windows 10 Edit Filename Path? Office 2010 32bit
Advanced Beginner
Edit Filename Path?
 
Join Date: Jun 2016
Posts: 44
Cyberseeker is on a distinguished road
Default Edit Filename Path?

I have a macro that I haven't used for a long time, and I would like to get it up and going again. It comes to a grinding halt where my code reads,


Code:
Workbooks.Open FileName:=fileloc
I receive a message, Run-time error '1004': and it tells me my file could not be found. Yes, Ive changed my file location, and its now up in the sky (onedrive) . Thats where I want it, but my question is: how do I edit my Filename? I dont even know where to find it, what less edit it. Alternatively, is it better to write the path directly into the macro?

Any help appreciated.
Reply With Quote
  #2  
Old 03-27-2017, 02:27 PM
Cyberseeker Cyberseeker is offline Edit Filename Path? Windows 10 Edit Filename Path? Office 2010 32bit
Advanced Beginner
Edit Filename Path?
 
Join Date: Jun 2016
Posts: 44
Cyberseeker is on a distinguished road
Default

Here is my error message. Fixing the path is probably easy but Im at a loss.

excelmacroerror.PNG
Reply With Quote
  #3  
Old 03-27-2017, 03:28 PM
Logit Logit is offline Edit Filename Path? Windows 10 Edit Filename Path? Office 2007
Expert
 
Join Date: Jan 2017
Posts: 587
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

Probably need to see all of your code in that macro rather than just one line.

However ... two probable causes:

#1 - The file is no longer where you remember it being and Excel can't find it.

#2 - Part of your code is missing.

Regarding #2 ... example code:

Code:
Sub ImportWorksheet() 
    ' This macro will import a file into this workbook 
    Sheets("Sheet1").Select 
    PathName = Range("D3").Value  '<--- could easily be the actual path instead of the path written to a cell
    Filename = Range("D4").Value  '<-- could be the actual filename instead
    TabName = Range("D5").Value 
    ControlFile = ActiveWorkbook.Name 
    Workbooks.Open Filename:=PathName & Filename 
    ActiveSheet.Name = TabName 
    Sheets(TabName).Copy After:=Workbooks(ControlFile).Sheets(1) 
    Windows(Filename).Activate 
    ActiveWorkbook.Close SaveChanges:=False 
    Windows(ControlFile).Activate 
End Sub
Note there is a reference made to Filename and Pathname so Excel knows
what is meant by Filename:=PathName & Filename

Does you code provide the reference for fileloc ?
Reply With Quote
  #4  
Old 03-27-2017, 04:40 PM
NoSparks NoSparks is offline Edit Filename Path? Windows 7 64bit Edit Filename Path? Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

Isn't your My Documents folder actually like this ?

C:\Users\Cyberseeker\Documents\
Reply With Quote
  #5  
Old 03-27-2017, 05:04 PM
Cyberseeker Cyberseeker is offline Edit Filename Path? Windows 10 Edit Filename Path? Office 2010 32bit
Advanced Beginner
Edit Filename Path?
 
Join Date: Jun 2016
Posts: 44
Cyberseeker is on a distinguished road
Default

Since I got Windows 10 and shunted my files around, it ended up like this:

Desktop\Cyberseeker\Onedrive\5L2F\Pricelist.xls

My problem is that I dont know where to edit my original code?
Reply With Quote
  #6  
Old 03-27-2017, 05:55 PM
Logit Logit is offline Edit Filename Path? Windows 10 Edit Filename Path? Office 2007
Expert
 
Join Date: Jan 2017
Posts: 587
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

The line highlighted is : Workbooks.Open FileName:=fileloc

fileloc is a variable name that is referenced somewhere up above that line.

It most likely looks like : set fileloc = "and the old file path here"

It should look like : set fileloc = "C:\Users\Cyberseeker\Documents\Pricelist.xlsx "


If you can't locate that line (set fileloc = "and the old file path here"), post the entire macro code here so we can review it.
Reply With Quote
  #7  
Old 03-28-2017, 01:03 AM
Cyberseeker Cyberseeker is offline Edit Filename Path? Windows 10 Edit Filename Path? Office 2010 32bit
Advanced Beginner
Edit Filename Path?
 
Join Date: Jun 2016
Posts: 44
Cyberseeker is on a distinguished road
Default

I found the path I was looking for. It was on a different sheet to where the macro button was. I changed it accordingly, and my PC now finds the path as expected. However, my notebook doesn't yet. Strange, because they are the same file on my Onedrive.

Thanks for the help. Im learning.
Reply With Quote
  #8  
Old 03-28-2017, 07:23 AM
Logit Logit is offline Edit Filename Path? Windows 10 Edit Filename Path? Office 2007
Expert
 
Join Date: Jan 2017
Posts: 587
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

You are welcome. Cheers
Reply With Quote
Reply

Tags
filename



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word does not show filename during edit es35 Word 5 10-29-2016 12:12 AM
use full path for filename ruggb Word 1 08-21-2015 05:10 AM
Edit Filename Path? How to: Have two templates cross-reference each other independent of filename path HighSierra Word 6 05-06-2015 07:04 PM
Edit Filename Path? Change old path to new path (batch) NobodysPerfect Word VBA 2 08-14-2014 10:09 PM
MarkAsFinal - 'Edit Anyway' edit popup issue GovindRS PowerPoint 1 06-20-2011 06:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:33 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft