VBA Substitute Drive Path for Cell.Value

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,109
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I'm working with the drive path within a sub:

VBA Code:
FSO.MoveFile Source:="C:\Users\Desktop\Test(2020).xlsm", Destination:=sMain & "\Test(2020).xlsm" ' copy and delete from source

I'm interested in a code that can indicate the name of the file as seen above referenced within the workbook itself.

For example:

Code:
FSO.MoveFile Source:="C:\Users\Desktop\ &ThisWorkBook.Sheets(1)Range("A1").Value", Destination:=sMain & "\&ThisWorkBook.Sheets(1)Range("A1").Value" ' copy and delete from source

This is the idea that I'm exploring:
&ThisWorkBook.Sheets(1)Range("A1").Value

where the drive path references the name of the file as a location in the workbook.

Please let me know, if this is possible.

Thank you,
pinaceous
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
AS you haven't provided ALL of your code, I'm guessing something like
VBA Code:
FSO.MoveFile Source:="C:\Users\Desktop\" & Sheets(1).Range("A1").Value & ", Destination:= sMain & "\" & Sheets(1).Range("A1").Value
Depends on what sMain holds though ?
 
Upvote 0
Hi Michael,

I'm glad that you posted. Here is the code that I'm working with:

VBA Code:
Sub CreateFolders()

Dim FSO As Object, sourceFolder As Object, file As Object

  Dim sPath As String, sMain As String, sFolder As String
  Dim i As Long

    Set FSO = CreateObject("Scripting.FileSystemObject")
    sPath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
    sMain = sPath & "\" & ThisWorkbook.Sheets(1).Range("B11").Value
        'T1
  If Dir(sMain, vbDirectory) <> "" Then 'if the folder exists
  'Do nothing
    MsgBox "Duplicate Folders!"

   
  Exit Sub

  Else ' 'if the folder not exists
      MkDir sMain

        FSO.MoveFile Source:="C:\Users\Desktop\ "& Sheets(1).Range("A1").Value & ", Destination:= sMain & "\" & Sheets(1).Range("A1").Value
       
    End If
   
Set FSO = Nothing

For i = 11 To 23
    sFolder = sMain & "\" & Sheets(1).Range("C" & i).Value
        'T1
    If Dir(sFolder) = "" Then
      MkDir sFolder
    End If
  Next


End Sub

I put in your line of the code from Post#2, could you help me with the syntax of it?

Thank you,
pinaceous.
 
Upvote 0
Sorry Pinaceous
Don't have Excel atm, hopefully someone will jump in and help out ...:mad::mad:
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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