Say yes and/or ignore all dialogue box pop ups

Macro_

New Member
Joined
Sep 3, 2014
Messages
35
Hi all, I've got a macro that runs and every time a new sheet is run a dialogue box comes up saying '.... template is already open. Are you sure to want to open.' and I have to manually click yes for all.
How do I make my macro say yes to all and/or ignore the dialogue box? This is my code
Code:
 '==========>>
 Option Explicit
 '---------->>
 Public Sub PassVariables()
      Dim WB As Workbook
      Dim SH As Worksheet
      Set WB = ThisWorkbook
      Set SH = WB.Sheets("Sheet1")
      Dim i As Variant
      For i = 2 To 151
      
     With SH
      Call Main(myYear:=.Range("A2").Value, _
                myQuarter:=CStr(.Range("B2").Value), _
                myFolder:=CStr(.Range("C2").Value), _
                mySaveAsFolder:=CStr(.Range("D" & i).Value), _
                mySaveAsName:=CStr(.Range("E" & i).Value), _
                blCreateFolder:=CStr(.Range("F" & i).Value))
     End With
Next
 
End Sub '---------->>

'---------->>
Public Sub Main(myYear As Variant, myQuarter As String, _
                   myFolder As String, _
                   mySaveAsFolder As String, _
                   mySaveAsName As String, _
                   Optional blCreateFolder As Boolean)
     Dim WB As Workbook
     Dim WS As Worksheet
     Dim spath As String
     Dim sSaveAsPath As String
     Dim sFilename As String
     Dim sFullname As String
     Dim aStr As String
    
     aStr = myQuarter & " " & myYear
     spath = "X:\SPECIFICFOLDER\" & myYear & "\" & aStr & "\TMT\" & myFolder
     sSaveAsPath = "X:\SPECIFICFOLDER\" & myYear & "\" & aStr & "\TMT\" & mySaveAsFolder
     sFilename = "ST" & aStr & ".xlsm"
     sFullname = spath & "\" & sFilename
     Workbooks.Open Filename:=sFullname, UpdateLinks:=0
     ActiveCell.Offset(-1, 0).FormulaR1C1 = mySaveAsName
     Set WS = ActiveSheet
     Set WB = Workbooks.Add(xlWBATWorksheet)
     WS.Range("A1:S84").Copy
     WB.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteValues
     WB.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteFormats
     Application.CutCopyMode = False
     
     If blCreateFolder Then
          MkDir sSaveAsPath
         blCreateFolder = False
     End If

     'ChDir sSaveAsPath
    With ActiveWorkbook
         .SaveAs Filename:=sSaveAsPath & "\" & mySaveAsName, _
                 FileFormat:=xlOpenXMLWorkbook, _
                 CreateBackup:=False
        .Close SaveChanges:=False
    End With

 End Sub
 '<<==========
 

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
Not sure - are you sure it's saving the right workbook file each time? Be sure of which workbook is active after the workbooks.open statement and then after the Workbooks.Add function.

You'll probably want to also change that workbooks.open statement to something like "set wb0 = Workbooks.Open(Filename:=sFullname, UpdateLinks:=0)" so that you can do a "wb0.close" after you're done with it.

Just noticed something- looks like you're using the same source workbook every time through the loop and just making a minor change and saving it with a different name. Is that the intention?

If so, you don't need to reopen it every time through the loop- it's already open the first time.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,984
Messages
6,128,110
Members
449,421
Latest member
AussieHobbo

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