excel vba - Want to rename mp3 files from 1 to words mentioned in column1 in that order -


rename mp3 file, using words in column in worksheet:

sub rename  dim integer  dim new_name string      i=1     while range("a1").offset(i,0)<>""     range("a1").offset(i-1,0).select     new_name=worksheets("sheet1").range("a1").offset(i-1, 0)      name "g:\" &i& ".mp3" as"g:\" & new_name & ".mp3"      = i+1     loop  end sub 

at line name "g:\" ... line highlighted in yellow.. , says error 53!

you can't declare old name new name. need file system object rename files. used movefile method rename file.

the as keyword used when declaring variable. dim variable_name as specific data_type instance dim idx integer

first add these things declarations

dim fso dim srcfile string dim destfile string 

then replace line

'name "g:\" &i& ".mp3" as"g:\" & new_name & ".mp3" 

with of this

srcfile = "g:\" & & ".mp3" destfile = "g:\" & new_name & ".mp3" set fso = createobject("scripting.filesystemobject")  if not fso.fileexists(srcfile)     msgbox srcfile & " not exist!", vbexclamation, "source file missing"  elseif not fso.fileexists(destfile)     call fso.movefile(srcfile, destfile)  else     msgbox destfile & file & " exists!", vbexclamation, "destination file exists"  end if  set fso = nothing 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -