Save WorkSheet as per Cell VALUE (keep original open, and do not open new)

TTUK

Board Regular
Joined
Apr 5, 2012
Messages
137
Hello all,

I am trying to achieve the following within VBA.

1. Save specific worksheet (IIR_temp) to a location shown in the cell in A1 on that page, which is a reference from another sheet =IIR_data!5 which looks like (\\server\report\test.xls)
2. Then have the sheet just be saved, and not to override the current spreadsheet which is open


At present this is what I have:

ActiveSheet.Copy ' Copies active sheet to a new workbook
ActiveSheet.SaveAs Range("A1").Value, xlOpenXMLWorkbookMacroEnabled


I just don't know how to get the formula to save the certain sheet in the specified location shown in A1, and allow me to return as I was in the original spreadsheet.

Hope someone can help me out on this.

Thank you!
 
A1 is =IIR_data!A12
B1 is =IIR_data!A10

The A1 is the file location, and B1 is the file name.

Thank you,
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
What the actual values, rather than the formulae?
 
Upvote 0
Hello Fluff,

For A1 is it = ="\\dataserver\ManagementSystem\Health & Safety Management System (HS)\Accident Incident Register (AIR)"
For B1 it is = =A8&B8&C8&D8&E8&F8

B1 is a combination of cells in a register that has been select and it reads (for example) - 05.01.2018_Incident Investigation Report

Thank you
 
Upvote 0
You're missing the final \ from the path name
try
Code:
ActiveSheet.Copy ' Copies active sheet to a new workbook
ActiveWorkbook.SaveAs Range("A1").Value & "\" & Range("B1").value, 56
ActiveWorkbook.Close
 
Upvote 0
Hello Fluff,

Apologies I copied the information incorrectly, the link in A1 does link to the file path wit hthe "" in.
="\\dataserver\ManagementSystem\Health & Safety Management System (HS)\Accident Incident Register (AIR)"

It still does not work unfortunately.
 
Upvote 0
Double check that there are spelling mistakes & leading/trailing spaces.
Also try this
Code:
ActiveSheet.Copy ' Copies active sheet to a new workbook
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Range("A1").Value & Range("B1").Value, 56
ActiveWorkbook.Close
Application.DisplayAlerts = True
 
Upvote 0
It takes the sheet and creates it as a new workbook (Book3) but doesn't have the file name nor has it saved in the location.

However this does throw up an error with this bit of code:

Code:
Public Sub Create_Links()

    Dim lastRow As Long
    Dim cell As Range
    
    'Create hyperlinks in column AW for each cell in column AW starting at AW8
    
    With Worksheets("Register")
        lastRow = .Cells(Rows.Count, "B").End(xlUp).Row
        For Each cell In .Range("A8:A" & lastRow)
            .Hyperlinks.Add anchor:=.Cells(cell.Row, "AW"), Address:="", TextToDisplay:="Create " & cell.Value & " folder"
        Next
    End With
    
End Sub

The above code allows when a selection is made in cell B on the sheet 'Register' it will create the 'Create (name) folder' here and allow me to automatically create a folder on our server based on the name/ID given.
I think Book 3 is looking for this piece of code perhaps? Not really sure what is going on!

Seems to be conflicting in some way?!

I really do appreciate all the support you have provided thus far!
 
Last edited:
Upvote 0
Could you supply the complete macro you are using that contains the saveas?
 
Upvote 0
Could you supply the complete macro you are using that contains the saveas?

Hello Fluff,

Here is the macro where I want to contain the SaveAs function of the worksheet.

A user can click on a specific line where the text says 'Raise Follow-up Form' it then opens a dialogue box, whereby the user selects 'Yes' it then copies data to be used in the IIR_temp worksheet.
I then need this worksheet to save like we have discussed.

Code:
Sub Followup_Confirm()     
    Dim Msg As String, Ans As Variant
     
    Msg = "Confirm you would like to raise a Follow-up form"
     
    Ans = MsgBox(Msg, vbYesNo)
     
    Select Case Ans
         
    Case vbYes
                        
        ' Copy date and paste in cell on row
        ActiveCell.FormulaR1C1 = "Form Raised"
        ActiveCell.Offset(0, 1).Select
        ActiveCell.FormulaR1C1 = "=R4C52"
        
        Selection.Copy
        
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Application.CutCopyMode = False
        
        ' Select the worksheet that is to be saved
        Sheets("IIR_temp").Select
        
        ActiveSheet.Copy ' Copies active sheet to a new workbook
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs Range("A1").Value & Range("B1").Value, 56
        ActiveWorkbook.Close
        Application.DisplayAlerts = True
         
    Case vbNo
GoTo Quit:
    End Select
     
Quit:
         
End Sub



Thanks,
 
Upvote 0
What sheet is active when you run that macro?
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,487
Members
448,967
Latest member
visheshkotha

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