Can't get folder to create on desktop. When debugging it shows no errors.

dallas2024

New Member
Joined
Oct 25, 2024
Messages
14
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Sub WO_SaveUpdate()
Dim WORow As Long, WOCol As Long
Dim AssignedTo As String, SharedFolder As String, FileName As String, FilePath As String

ActiveWorkbook.Save
   
   Application.ScreenUpdating = False
   
With Sheet1
 If .Range("D4").Value = Empty Or .Range("H4").Value = Empty Or .Range("D10").Value = Empty Or .Range("C15").Value = Empty Then
    MsgBox "Please Complete Yellow Boxes"
    Exit Sub
 End If
 End With


With Sheet3
If .Range("C4").Value = Empty Then
    MsgBox "Please add in a shared folder location"
    Exit Sub
End If
End With

With Sheet2
If Worksheets("WO Data").Range("B11").Value = True Then 'new WOrk order
    WORow = .Range("C99999").End(xlUp).Row + 1  'First Avail. Row
Else ' Existing Work Order
End If
End With


With Sheet1
 For WOCol = 3 To 11
   Sheet2.Cells(WORow, WOCol).Value = .Range(.Cells(30, WOCol).Value).Value 'Place values in WO Row
    Sheet4.Range(.Cells(29, WOCol).Value).Value = .Range(.Cells(30, WOCol).Value).Value 'Place Values in WO Template
 Next WOCol
 Sheet2.Range("B11").Value = False 'Set new WO to false
Sheet2.Range("B12").Value = WORow


'Create/Update Work Order in Shared folder if status is Open
If .Range("D8").Value = "Open" Then
    AssignedTo = .Range("H4").Value 'Assigned To
    SharedFolder = Sheet3.Range("C4").Value 'Shared Folder location
    FileName = "Work Order_" & .Range("D6").Value 'File Name Work Order & #
    If Dir(SharedFolder & "\" & AssignedTo, vbDirectory) = "" Then MkDir (SharedFolder & "\" & AssignedTo) 'Create Folder if it does not exist
    FilePath = SharedFolder & "\" & AssignedTo & "\" & FileName & ".xlsx"
    On Error Resume Next
    Kill (FilePath)
    On Error GoTo 0
    Sheet4.Range("A1:B26").Copy
    Workbooks.Add
    ActiveWorkbook.Sheets(1).Range("A1").PasteSpecial xlPasteAll
    ActiveWorkbook.Sheets(1).Range("A1").PasteSpecial xlPasteColumnWidths
    ActiveWorkbook.SaveAs FilePath
    ActiveWorkbook.Close False
    Sheet2.Range("G" & WORow).Value = Now 'Update Assigned On to Current date & Time
    
    Application.ScreenUpdating = True
    
    ActiveWorkbook.Save
    
End If

End With
End Sub
 
I would like the code to make a folder and save the file inside the folder it makes and yes sheet 1 is Work Order and so on
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
As per your explanation in Post #11
Change references as required.
Code:
Sub Like_So()
Dim pth As String
pth = CreateObject("wscript.shell").specialfolders(10) & "\Whatever Name You Want The Folder To Be"
MkDir pth
ThisWorkbook.SaveAs pth & "\" & ThisWorkbook.Name
End Sub
 
Upvote 0
VBA Code:
  FileName = "Work Order_" & .Range("D6").Value 'File Name Work Order & #(This Range is on Pic 1 it will change everytime work order is generated)
This is my file name inside the folder after it creates the folder and saves the file.

VBA Code:
FilePath = SharedFolder & "\" & AssignedTo & "\" & FileName & ".xlsx"(Pic 1 shows assigned to its a drop down box i can choose)

I need to save it as the location and assigned to(which is folder name) and file name with extension .xlsx
 

Attachments

  • Pic 1.PNG
    Pic 1.PNG
    81.4 KB · Views: 3
Upvote 0
Do you want to save a sheet into the folder on the desktop as a workbook or the whole workbook with the 4 sheets ("Work Order", "WO Data", "Name" and "WO") as an .xlsx type workbook?
 
Upvote 0
If the Folder "AssignedTo" does not exist on the Desktop, it will create it.
The whole Workbook with all 4 Sheets will be saved in the "AssignedTo" Folder.
The File Name will be as the Value in "D6" in Sheet "Work Order".
It will be saved as a non macro (.xlsx) type file.
If there is a File with the same name in the Folder already, it will tell you to change the filename and exit the macro.
Code:
Sub Like_So_B()
Dim pth As String, fn As String
pth = CreateObject("wscript.shell").specialfolders(10) & "\AssignedTo"
fn = "Work Order_" & Sheets("Sheet1").Range("D6").Value & ".xlsx"
If Dir(pth, vbDirectory) = "" Then MkDir pth
If Dir(pth & "\" & fn) <> "" Then MsgBox "Duplicate File Name! Start Over With Different File Name.": Exit Sub
Application.DisplayAlerts = False
    ThisWorkbook.SaveAs pth & "\" & fn, FileFormat:=51
Application.DisplayAlerts = True
End Sub
 
Upvote 0
I removed the -If .Range("D8").Value = "Open" Then
Got a error on my folder, but the Shared folder is going to sheet 3
The assigned to is on sheet 1
 

Attachments

  • directory error.PNG
    directory error.PNG
    147.9 KB · Views: 1
  • sheet3.PNG
    sheet3.PNG
    66.9 KB · Views: 1
  • assigned to.PNG
    assigned to.PNG
    79.4 KB · Views: 1
Upvote 0
I want to save the WO tab into the new folder being created and the WO file name save is using "FileName = "Work Order_" & .Range("D6").Value 'File Name Work Order & #"
 

Attachments

  • WO tab.PNG
    WO tab.PNG
    86.7 KB · Views: 2
Upvote 0
I got it to save the folder and file on desktop but I had to delete the "If .Range("D8").Value = "Open" Then"
Also change-SharedFolder = Sheet3.Range("C4").Value 'Shared Folder location to SharedFolder = "C:\Users\Admin\Desktop"
I was pulling Shared folder from sheet3 pic below and would like to continue doing it that way if possible and also I need my "If .Range("D8").Value = "Open" Then - also if its possible on Pic1 below
 

Attachments

  • sheet3.PNG
    sheet3.PNG
    66.9 KB · Views: 2
  • Pic 1.PNG
    Pic 1.PNG
    81.4 KB · Views: 2
Upvote 0
We have 19 posts and nothing accomplished yet.
As requested previously, explain in a concise manner what you want to achieve. That means step by step including cell addresses, sheet names and whatever you have, in the order you would do it manually. No Pictures anymore.
 
Upvote 0

Forum statistics

Threads
1,223,101
Messages
6,170,116
Members
452,302
Latest member
TaMere

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