Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Ozzie via OfficeKB.com
 
Posts: n/a
Default Macro to save a file with ref to a tick box

What I am struggling with is being able to write a macro that performs the
following;

will save a workbook to a specified folder, but, adds 1) a date stamp and 2)
a piece of text from the 1st sheet of the workbook to the saved file name.

Once the macro has run and has saved the workbook I would like a message box
to say " you have now saved your file" and to have the choice to close the
workbook?

any thing would be appreciated,

many thanks

David

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200601/1
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Macro to save a file with ref to a tick box

Maybe something like this:

Option Explicit
Sub testme()

Dim myFileName As String
Dim resp As Long

With ActiveWorkbook
myFileName = "C:\my documents\excel\" _
& .Worksheets("sheet1").Range("a1").Value _
& "_" & Format(Now, "yyyymmdd_hhmmss") & ".xls"

.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal
resp = MsgBox(prompt:="Wanna close this workbook?", _
Buttons:=vbYesNo)

If resp = vbYes Then
.Close savechanges:=False
End If
End With

End Sub

You may want add some validity checks for what's in that cell.



"Ozzie via OfficeKB.com" wrote:

What I am struggling with is being able to write a macro that performs the
following;

will save a workbook to a specified folder, but, adds 1) a date stamp and 2)
a piece of text from the 1st sheet of the workbook to the saved file name.

Once the macro has run and has saved the workbook I would like a message box
to say " you have now saved your file" and to have the choice to close the
workbook?

any thing would be appreciated,

many thanks

David

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200601/1


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
Ozzie via OfficeKB.com
 
Posts: n/a
Default Macro to save a file with ref to a tick box

Dave, many thanks it works a treat

Dave Peterson wrote:
Maybe something like this:

Option Explicit
Sub testme()

Dim myFileName As String
Dim resp As Long

With ActiveWorkbook
myFileName = "C:\my documents\excel\" _
& .Worksheets("sheet1").Range("a1").Value _
& "_" & Format(Now, "yyyymmdd_hhmmss") & ".xls"

.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal
resp = MsgBox(prompt:="Wanna close this workbook?", _
Buttons:=vbYesNo)

If resp = vbYes Then
.Close savechanges:=False
End If
End With

End Sub

You may want add some validity checks for what's in that cell.

What I am struggling with is being able to write a macro that performs the
following;

[quoted text clipped - 11 lines]

David



--
Message posted via http://www.officekb.com
  #4   Report Post  
Posted to microsoft.public.excel.misc
Ozzie via OfficeKB.com
 
Posts: n/a
Default Macro to save a file with ref to a tick box

Dave,

Could I ask one more question, the code below works fine and have tailored it
into my vba statement, however the last thing i need to do, which I haven't
the faintest idea how, is to;

when the macro is run (in excel) from a button, I need the text on the button
to change to say "you have now saved and sent your data"

any idea's??

thanks again for all your help, cheers


Dave Peterson wrote:
Maybe something like this:

Option Explicit
Sub testme()

Dim myFileName As String
Dim resp As Long

With ActiveWorkbook
myFileName = "C:\my documents\excel\" _
& .Worksheets("sheet1").Range("a1").Value _
& "_" & Format(Now, "yyyymmdd_hhmmss") & ".xls"

.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal
resp = MsgBox(prompt:="Wanna close this workbook?", _
Buttons:=vbYesNo)

If resp = vbYes Then
.Close savechanges:=False
End If
End With

End Sub

You may want add some validity checks for what's in that cell.

What I am struggling with is being able to write a macro that performs the
following;

[quoted text clipped - 11 lines]

David



--
Message posted via http://www.officekb.com
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Macro to save a file with ref to a tick box

I would show the Forms toolbar and use the button from that toolbar--not a
commandbutton from the Control toolbox toolbar.

Then assign the macro to that button.

But I think you'll want to add a bit.

Option Explicit
Sub testme()

Dim myFileName As String
Dim resp As Long
Dim myBTN As Button

With ActiveWorkbook
myFileName = "C:\my documents\excel\" _
& .Worksheets("sheet1").Range("a1").Value _
& "_" & Format(Now, "yyyymmdd_hhmmss") & ".xls"

.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal
resp = MsgBox(prompt:="Wanna close this workbook?", _
Buttons:=vbYesNo)

If resp = vbYes Then
.Close savechanges:=False
End If

Set myBTN = ActiveSheet.Buttons(Application.Caller)
myBTN.Caption = "You have now saved and sent your data"
End With

End Sub

Sub auto_open()
Worksheets("sheet1").Buttons("button 1").Caption _
= "Click me to save and send your data"
End Sub

The auto_open routine will run when the workbook opens. Change the worksheet
name and button name to what you need.

"Ozzie via OfficeKB.com" wrote:

Dave,

Could I ask one more question, the code below works fine and have tailored it
into my vba statement, however the last thing i need to do, which I haven't
the faintest idea how, is to;

when the macro is run (in excel) from a button, I need the text on the button
to change to say "you have now saved and sent your data"

any idea's??

thanks again for all your help, cheers

Dave Peterson wrote:
Maybe something like this:

Option Explicit
Sub testme()

Dim myFileName As String
Dim resp As Long

With ActiveWorkbook
myFileName = "C:\my documents\excel\" _
& .Worksheets("sheet1").Range("a1").Value _
& "_" & Format(Now, "yyyymmdd_hhmmss") & ".xls"

.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal
resp = MsgBox(prompt:="Wanna close this workbook?", _
Buttons:=vbYesNo)

If resp = vbYes Then
.Close savechanges:=False
End If
End With

End Sub

You may want add some validity checks for what's in that cell.

What I am struggling with is being able to write a macro that performs the
following;

[quoted text clipped - 11 lines]

David



--
Message posted via http://www.officekb.com


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot save Project file as MS Access file Jumpinjackflash Excel Discussion (Misc queries) 1 January 11th 06 11:35 PM
Weird File Open/Save As Behavior [email protected] Excel Discussion (Misc queries) 0 December 9th 05 02:26 AM
Macro to save a file as ynissel Excel Discussion (Misc queries) 4 May 26th 05 02:48 PM
Macro excel save mrbalaje Excel Discussion (Misc queries) 1 May 12th 05 06:27 PM
This one is tricky....Macro to save file as cell value x in di Andy Excel Discussion (Misc queries) 4 November 26th 04 08:52 AM


All times are GMT +1. The time now is 10:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"