PC Review


Reply
Thread Tools Rate Thread

Determine whether the user has saved the file?

 
 
Tim879
Guest
Posts: n/a
 
      5th Mar 2008
Hey

Does anyone know how to determine if the user has saved the excel file
they are working in?

I have a macro that saves the current tab as a CSV file for upload,
but if the user hasn't saved the file the code doesn't work.

the code is posted below.
Thanks
Tim
Sub Save_As_CSV()
'saves the current tab as a CSV tab.
Dim CurrentDay, CurrentMonth, CurrentSheet, CurrentWBName, CurrentDate
As String
Dim continue As Integer
Dim NewFileName As String


continue = MsgBox("Do you want to save this tab as a CSV file?",
vbYesNo)

If continue = vbYes Then

Dim wsht As Worksheet


Application.DisplayAlerts = False
Application.ScreenUpdating = False

CurrentWBName = ActiveWorkbook.FullName
CurrentSheet = ActiveSheet.Name

Set wsht = Sheets.Add
wsht.Name = "CSV-Temp"


wsht.Select
Cells.Select
Selection.NumberFormat = "@"

Sheets(CurrentSheet).Select

Cells.Select
Selection.Copy

wsht.Select

Selection.PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False ' paste values


NewFileName = WorksheetFunction.Substitute(CurrentWBName,
".xls", "") & ".csv"
' NewFileName = Left(CurrentWBName, Len(CurrentWBName) - 4) &
".csv"

MsgBox NewFileName
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
NewFileName, FileFormat:=xlCSV, CreateBackup:=False


Sheets(CurrentSheet).Select

wsht.Delete

ActiveWorkbook.SaveAs Filename:= _
CurrentWBName, FileFormat:=xlNormal, CreateBackup:=False

Application.ScreenUpdating = True
Application.DisplayAlerts = True

Range("a1").Select

MsgBox ("CSV saved under: " & NewFileName)

Else
MsgBox ("Cancelled")
End If
End Sub
 
Reply With Quote
 
 
 
 
PCLIVE
Guest
Posts: n/a
 
      5th Mar 2008
Maybe something like this:

If ActiveWorkbook.Saved = True _
Then
MsgBox ("Workbook has been saved.")
Else
MsgBox ("Workbook has NOT been saved.")
End If

HTH,
Paul

--

"Tim879" <(E-Mail Removed)> wrote in message
news:ed51f089-0680-4213-8674-(E-Mail Removed)...
> Hey
>
> Does anyone know how to determine if the user has saved the excel file
> they are working in?
>
> I have a macro that saves the current tab as a CSV file for upload,
> but if the user hasn't saved the file the code doesn't work.
>
> the code is posted below.
> Thanks
> Tim
> Sub Save_As_CSV()
> 'saves the current tab as a CSV tab.
> Dim CurrentDay, CurrentMonth, CurrentSheet, CurrentWBName, CurrentDate
> As String
> Dim continue As Integer
> Dim NewFileName As String
>
>
> continue = MsgBox("Do you want to save this tab as a CSV file?",
> vbYesNo)
>
> If continue = vbYes Then
>
> Dim wsht As Worksheet
>
>
> Application.DisplayAlerts = False
> Application.ScreenUpdating = False
>
> CurrentWBName = ActiveWorkbook.FullName
> CurrentSheet = ActiveSheet.Name
>
> Set wsht = Sheets.Add
> wsht.Name = "CSV-Temp"
>
>
> wsht.Select
> Cells.Select
> Selection.NumberFormat = "@"
>
> Sheets(CurrentSheet).Select
>
> Cells.Select
> Selection.Copy
>
> wsht.Select
>
> Selection.PasteSpecial Paste:=xlPasteValues,
> Operation:=xlNone, SkipBlanks _
> :=False, Transpose:=False ' paste values
>
>
> NewFileName = WorksheetFunction.Substitute(CurrentWBName,
> ".xls", "") & ".csv"
> ' NewFileName = Left(CurrentWBName, Len(CurrentWBName) - 4) &
> ".csv"
>
> MsgBox NewFileName
> Application.DisplayAlerts = False
> ActiveWorkbook.SaveAs Filename:= _
> NewFileName, FileFormat:=xlCSV, CreateBackup:=False
>
>
> Sheets(CurrentSheet).Select
>
> wsht.Delete
>
> ActiveWorkbook.SaveAs Filename:= _
> CurrentWBName, FileFormat:=xlNormal, CreateBackup:=False
>
> Application.ScreenUpdating = True
> Application.DisplayAlerts = True
>
> Range("a1").Select
>
> MsgBox ("CSV saved under: " & NewFileName)
>
> Else
> MsgBox ("Cancelled")
> End If
> End Sub



 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      5th Mar 2008
A newworkbook won't have xls in the file name try this instead

if instr(CurrentWBName,"xls") > 0 then
NewFileName = WorksheetFunction.Substitute(CurrentWBName,
".xls", "") & ".csv"
else
NewFileName = CurrentWBName & ".csv"
end if

"Tim879" wrote:

> Hey
>
> Does anyone know how to determine if the user has saved the excel file
> they are working in?
>
> I have a macro that saves the current tab as a CSV file for upload,
> but if the user hasn't saved the file the code doesn't work.
>
> the code is posted below.
> Thanks
> Tim
> Sub Save_As_CSV()
> 'saves the current tab as a CSV tab.
> Dim CurrentDay, CurrentMonth, CurrentSheet, CurrentWBName, CurrentDate
> As String
> Dim continue As Integer
> Dim NewFileName As String
>
>
> continue = MsgBox("Do you want to save this tab as a CSV file?",
> vbYesNo)
>
> If continue = vbYes Then
>
> Dim wsht As Worksheet
>
>
> Application.DisplayAlerts = False
> Application.ScreenUpdating = False
>
> CurrentWBName = ActiveWorkbook.FullName
> CurrentSheet = ActiveSheet.Name
>
> Set wsht = Sheets.Add
> wsht.Name = "CSV-Temp"
>
>
> wsht.Select
> Cells.Select
> Selection.NumberFormat = "@"
>
> Sheets(CurrentSheet).Select
>
> Cells.Select
> Selection.Copy
>
> wsht.Select
>
> Selection.PasteSpecial Paste:=xlPasteValues,
> Operation:=xlNone, SkipBlanks _
> :=False, Transpose:=False ' paste values
>
>
> NewFileName = WorksheetFunction.Substitute(CurrentWBName,
> ".xls", "") & ".csv"
> ' NewFileName = Left(CurrentWBName, Len(CurrentWBName) - 4) &
> ".csv"
>
> MsgBox NewFileName
> Application.DisplayAlerts = False
> ActiveWorkbook.SaveAs Filename:= _
> NewFileName, FileFormat:=xlCSV, CreateBackup:=False
>
>
> Sheets(CurrentSheet).Select
>
> wsht.Delete
>
> ActiveWorkbook.SaveAs Filename:= _
> CurrentWBName, FileFormat:=xlNormal, CreateBackup:=False
>
> Application.ScreenUpdating = True
> Application.DisplayAlerts = True
>
> Range("a1").Select
>
> MsgBox ("CSV saved under: " & NewFileName)
>
> Else
> MsgBox ("Cancelled")
> End If
> End Sub
>

 
Reply With Quote
 
Tim879
Guest
Posts: n/a
 
      5th Mar 2008
Who new it was that easy??

thanks man.

Have a great day!
Tim
On Mar 5, 10:14 am, "PCLIVE" <pclive(RemoveThis)@cox.net> wrote:
> Maybe something like this:
>
> If ActiveWorkbook.Saved = True _
> Then
> MsgBox ("Workbook has been saved.")
> Else
> MsgBox ("Workbook has NOT been saved.")
> End If
>
> HTH,
> Paul
>
> --
>
> "Tim879" <tim...@gmail.com> wrote in message
>
> news:ed51f089-0680-4213-8674-(E-Mail Removed)...
>
> > Hey

>
> > Does anyone know how to determine if the user has saved the excel file
> > they are working in?

>
> > I have a macro that saves the current tab as a CSV file for upload,
> > but if the user hasn't saved the file the code doesn't work.

>
> > the code is posted below.
> > Thanks
> > Tim
> > Sub Save_As_CSV()
> > 'saves the current tab as a CSV tab.
> > Dim CurrentDay, CurrentMonth, CurrentSheet, CurrentWBName, CurrentDate
> > As String
> > Dim continue As Integer
> > Dim NewFileName As String

>
> > continue = MsgBox("Do you want to save this tab as a CSV file?",
> > vbYesNo)

>
> > If continue = vbYes Then

>
> > Dim wsht As Worksheet

>
> > Application.DisplayAlerts = False
> > Application.ScreenUpdating = False

>
> > CurrentWBName = ActiveWorkbook.FullName
> > CurrentSheet = ActiveSheet.Name

>
> > Set wsht = Sheets.Add
> > wsht.Name = "CSV-Temp"

>
> > wsht.Select
> > Cells.Select
> > Selection.NumberFormat = "@"

>
> > Sheets(CurrentSheet).Select

>
> > Cells.Select
> > Selection.Copy

>
> > wsht.Select

>
> > Selection.PasteSpecial Paste:=xlPasteValues,
> > Operation:=xlNone, SkipBlanks _
> > :=False, Transpose:=False ' paste values

>
> > NewFileName = WorksheetFunction.Substitute(CurrentWBName,
> > ".xls", "") & ".csv"
> > ' NewFileName = Left(CurrentWBName, Len(CurrentWBName) - 4) &
> > ".csv"

>
> > MsgBox NewFileName
> > Application.DisplayAlerts = False
> > ActiveWorkbook.SaveAs Filename:= _
> > NewFileName, FileFormat:=xlCSV, CreateBackup:=False

>
> > Sheets(CurrentSheet).Select

>
> > wsht.Delete

>
> > ActiveWorkbook.SaveAs Filename:= _
> > CurrentWBName, FileFormat:=xlNormal, CreateBackup:=False

>
> > Application.ScreenUpdating = True
> > Application.DisplayAlerts = True

>
> > Range("a1").Select

>
> > MsgBox ("CSV saved under: " & NewFileName)

>
> > Else
> > MsgBox ("Cancelled")
> > End If
> > End Sub


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Mar 2008
People can have some strange template names that would include the string "xls".

I'd look at the path.

A workbook that's never been saved won't have a path:

if activeworkbook.path = "" then
'never saved
else
'it's been saved at least once
end if

Joel wrote:
>
> A newworkbook won't have xls in the file name try this instead
>
> if instr(CurrentWBName,"xls") > 0 then
> NewFileName = WorksheetFunction.Substitute(CurrentWBName,
> ".xls", "") & ".csv"
> else
> NewFileName = CurrentWBName & ".csv"
> end if
>
> "Tim879" wrote:
>
> > Hey
> >
> > Does anyone know how to determine if the user has saved the excel file
> > they are working in?
> >
> > I have a macro that saves the current tab as a CSV file for upload,
> > but if the user hasn't saved the file the code doesn't work.
> >
> > the code is posted below.
> > Thanks
> > Tim
> > Sub Save_As_CSV()
> > 'saves the current tab as a CSV tab.
> > Dim CurrentDay, CurrentMonth, CurrentSheet, CurrentWBName, CurrentDate
> > As String
> > Dim continue As Integer
> > Dim NewFileName As String
> >
> >
> > continue = MsgBox("Do you want to save this tab as a CSV file?",
> > vbYesNo)
> >
> > If continue = vbYes Then
> >
> > Dim wsht As Worksheet
> >
> >
> > Application.DisplayAlerts = False
> > Application.ScreenUpdating = False
> >
> > CurrentWBName = ActiveWorkbook.FullName
> > CurrentSheet = ActiveSheet.Name
> >
> > Set wsht = Sheets.Add
> > wsht.Name = "CSV-Temp"
> >
> >
> > wsht.Select
> > Cells.Select
> > Selection.NumberFormat = "@"
> >
> > Sheets(CurrentSheet).Select
> >
> > Cells.Select
> > Selection.Copy
> >
> > wsht.Select
> >
> > Selection.PasteSpecial Paste:=xlPasteValues,
> > Operation:=xlNone, SkipBlanks _
> > :=False, Transpose:=False ' paste values
> >
> >
> > NewFileName = WorksheetFunction.Substitute(CurrentWBName,
> > ".xls", "") & ".csv"
> > ' NewFileName = Left(CurrentWBName, Len(CurrentWBName) - 4) &
> > ".csv"
> >
> > MsgBox NewFileName
> > Application.DisplayAlerts = False
> > ActiveWorkbook.SaveAs Filename:= _
> > NewFileName, FileFormat:=xlCSV, CreateBackup:=False
> >
> >
> > Sheets(CurrentSheet).Select
> >
> > wsht.Delete
> >
> > ActiveWorkbook.SaveAs Filename:= _
> > CurrentWBName, FileFormat:=xlNormal, CreateBackup:=False
> >
> > Application.ScreenUpdating = True
> > Application.DisplayAlerts = True
> >
> > Range("a1").Select
> >
> > MsgBox ("CSV saved under: " & NewFileName)
> >
> > Else
> > MsgBox ("Cancelled")
> > End If
> > End Sub
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Determine which user has write access to a file? James Ravenswood Microsoft Excel Programming 0 7th Mar 2011 01:00 AM
How can I determine what user created a file in .net 1.1 Keith Microsoft VB .NET 1 9th Jan 2008 07:47 PM
Determine who saved the file aaronfude@gmail.com Windows XP General 1 6th Jun 2006 01:18 AM
How to determine in batch-file, if user is administrator Heiko Pliefke Microsoft Windows 2000 CMD Promt 3 4th Aug 2005 05:42 PM
How to determine total file size per User? Nestor Microsoft Windows 2000 Active Directory 1 16th Oct 2003 09:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:48 AM.