workbook path

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
529
was playing around with workbook.path
I get the path from a file that has been saved, but get nothing from a file that hasn't been saved (new blank workbook). I wanted to write a test that would say something like If wb.path = "" then....
Doesn't work though. Why is that?

I even tried to say If wb.saved = false then
when it gets to the workbook in question (looping); it's wont trip over any of my if's..... so How am I to know if a file hasnt ever been saved?

works for all of the other files that have been saved before.
 
Last edited:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
my code
Code:
    Dim wb As Workbook
    Dim TheApp As Object
    On Error GoTo nextapp
    Set TheApp = GetObject(, "Excel.Application")
    
    Call dbOn
        For Each wb In TheApp.Workbooks
            
            
            'MsgBox Len(wb.Path)
            MsgBox wb.Saved
            
            MsgBox wb.Name
            
            'MsgBox wb.Saved
            
            'MsgBox wb.Path
            
If wb.Path = True Then MsgBox "bob"
            'If wb.Path = "" Then MsgBox "has never been saved"
            'If wb.Saved = False Then MsgBox "not saved"
            'If objXLWorkbook.ReadOnly = True Then MsgBox "is read only"
        Next wb
    
nextapp:
    Call dbOff
    Set TheApp = Nothing
 
Upvote 0
Basically what I'm trying to accomplish is if a user has 20 workbooks open; I want my code to go through and save unsaved files, close read only files, and detect new workbooks that haven't been saved and save them as. My looping doesn't seem to include workbooks that have never been saved, which I'm unsure as to why.

Code:
Sub excel2()
    Dim wb As Workbook
    Dim TheApp As Object
    On Error GoTo nextapp
    Set TheApp = GetObject(, "Excel.Application")
    
    Call dbOn
        For Each wb In TheApp.Workbooks
            ' do some things here
            If wb.ReadOnly = True Then
                wb.Close
                GoTo done
            End If
            If Not wb.Saved Then
                wb.Save
                GoTo done
            End If
            'wb.path
done:
        Next wb
    
nextapp:
    Call dbOff
    Set TheApp = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,435
Messages
6,055,353
Members
444,781
Latest member
rishivar

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