Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 10th, 2014, 06:22 PM
Authorized User
 
Join Date: Jan 2012
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with code

First problem.
Code:
Private Sub cmdbtnFilesave_Click() 
    If MsgBox("Would you like to save this file now?", Title:="Save File", Buttons:=vbCritical + vbYesNo) = vbYes Then 
        FileToSave = Application.GetSaveAsFilename("Tie Testing" & Format(Sheet1.Range("A1"), "mmmddyyyy" & "TO" & Format(Sheet5.Range("v1"), "mmmddyyyyy")), Filefilter:="Microsoft Office Excel Workbook(*.xlsx),*.xlsx", Title:="Save File") 
        If FileToSave <> False Then 
            ActiveWorkbook.SaveAs FileToSave, FileFormat:=xlNormal 
        End If 
    End If 
End Sub
The above code is embedded into an activex command button. When I click on the command button in the cell, it displays the message box when I click yes, displays a "Run-time error '424': Object required."
The line "FileToSave = Application.GetSaveAsFilename("Testing" & Format(Sheet1.Range("A1"), "mmmddyyyy" & "TO" & Format(Sheet5.Range("v1"), "mmmddyyyyy")), Filefilter:="Microsoft Office Excel Workbook(*.xlsx),*.xlsx", Title:="Save File")" is highlighted in yellow. Did I code this wrong? Thanks.
 
Old March 10th, 2014, 06:40 PM
Authorized User
 
Join Date: Jan 2012
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Figured out where I went wrong. This code goes from sheet1 to sheet5, I only had the default of sheet1-3 displayed, no sheet5. This brings up another issue. The date will always be in row A. Is there a way for excel to loop through the sheets and range(A:A) and find the last sheet used and the last cell within that range and how can I substitute "Format(Sheet5.Range("v1")..." with the last sheet used and the last cell with a date on that sheet. Hope that makes sense. Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to save html page source code? Jaymond Flurrie Access VBA 2 July 2nd, 2019 06:04 PM
Difference between downloaded lesson code and code in book Alatha BOOK: Beginning HTML and CSS (published March 2013) 2 August 7th, 2013 08:34 PM
Function to convert CUSIP code to ISIN code ... cusipconv() amkh8857 Excel VBA 1 March 28th, 2013 02:37 AM
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.