Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-21-2018, 10:54 AM
sg11 sg11 is offline Using Word VBA to change file names in a directory Windows 7 64bit Using Word VBA to change file names in a directory Office 2010 64bit
Novice
Using Word VBA to change file names in a directory
 
Join Date: Mar 2018
Posts: 5
sg11 is on a distinguished road
Default Using Word VBA to change file names in a directory

I am trying to use


Name oldFile NewFile
But it fails because the Name is Identified as a String Variable with the value "Microsoft Office". This is not a variable that I entered, could not find where this was declared. Unable to change. It is constant.
Did not find any other way to rename files.
Help..?

Last edited by sg11; 03-22-2018 at 04:27 AM. Reason: Solved
Reply With Quote
  #2  
Old 03-21-2018, 06:53 PM
Guessed's Avatar
Guessed Guessed is offline Using Word VBA to change file names in a directory Windows 10 Using Word VBA to change file names in a directory Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You forgot to include an as between the oldfile and newfile
Code:
Name oldFile As NewFile
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 03-21-2018, 09:33 PM
sg11 sg11 is offline Using Word VBA to change file names in a directory Windows 7 64bit Using Word VBA to change file names in a directory Office 2010 64bit
Novice
Using Word VBA to change file names in a directory
 
Join Date: Mar 2018
Posts: 5
sg11 is on a distinguished road
Default No I did not in the VBA

Just forgot to add it here ...
Attached Images
File Type: jpg nameOldasNew.JPG (51.4 KB, 15 views)

Last edited by sg11; 03-21-2018 at 09:39 PM. Reason: want to add a file
Reply With Quote
  #4  
Old 03-21-2018, 10:58 PM
Guessed's Avatar
Guessed Guessed is offline Using Word VBA to change file names in a directory Windows 10 Using Word VBA to change file names in a directory Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

In that example you haven't populated the two string variables so it would struggle to work...
Code:
Sub aTest()
  Dim oldFile As String, newFile As String
  oldFile = "C:\Work\My Pictures\image1.wmf"
  newFile = "C:\Work\My Pictures\image2.wmf"
  Name oldFile As newFile 
End Sub
I must say I am surprised this is a valid command to rename a file. Name 'should' be a reserved word and can be used to show the name of the application
ie
debug.print Application.Name
debug.print Name
Both the above lines would return a string that shows the name of the current application.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 03-22-2018, 04:25 AM
sg11 sg11 is offline Using Word VBA to change file names in a directory Windows 7 64bit Using Word VBA to change file names in a directory Office 2010 64bit
Novice
Using Word VBA to change file names in a directory
 
Join Date: Mar 2018
Posts: 5
sg11 is on a distinguished road
Default Solved

Name command works
My problem was that
newName = "xxxx12 .png"
with space. When I removed the space it works.
Thanks
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Word VBA to change file names in a directory Extracting list of embedded image file names from Word 2016 erik@haagensen.no Word VBA 5 08-19-2017 11:02 PM
Using Word VBA to change file names in a directory How capture a folder's file names to a file? BobKnepper Word 2 05-22-2016 07:30 AM
Using Word VBA to change file names in a directory Copy and Paste from File to File but File Names always change aaronbauer1980 Excel Programming 1 04-15-2016 05:53 PM
Using Word VBA to change file names in a directory Replacing jpg file in each file of a directory hklein Word VBA 4 10-14-2013 04:40 PM
Using Word VBA to change file names in a directory Change order of names to LAST / FIRST ? Jack R Outlook 1 07-05-2010 08:50 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:58 AM.


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