JDSchmidt1977
New Member
- Joined
- May 3, 2018
- Messages
- 3
Hello Everyone,
I'm looking for some help. Before going in the details, I would like to clarify that I am a novice at VBA. I'm trying to do the following:
I have a couple of tables that are updated everyday. I have a query built out of power query that consolidates these to tables into a report. What I want to do is at the push of a button, refresh the query, copy the report into a new workbook, save that workbook in a specific location, and return the cursor to cell A1 in the original workbook.
So far I have created a form control button, recorded a macro that does everything as described above and also deletes the button on the new workbook, and assigned the macro to the button. When I run it everything works as needed; however, the button on the original file duplicates itself, and when I open the newly created file, the original button is gone, but the duplicated button now appears.
Does anyone know why this might be the case and what I can do about it? Here is the code from my Macro if it helps.......
Sub Macro1()
'
' Macro1 Macro
'
'
Range("B2").Select
Sheets("Query").Select
ActiveSheet.Buttons.Add(939, 52.5, 105, 47.25).Select
Sheets("Query").Copy
ActiveSheet.Shapes.Range(Array("Button 1")).Select
Selection.Delete
ActiveWindow.SmallScroll Down:=-9
ChDir "F:"
ActiveWorkbook.SaveAs Filename:="F:\Test.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
Range("Test_Data_2[[#Headers],[Transaction ID]]").Select
End Sub
Thanks in Advance,
Jonathan
I'm looking for some help. Before going in the details, I would like to clarify that I am a novice at VBA. I'm trying to do the following:
I have a couple of tables that are updated everyday. I have a query built out of power query that consolidates these to tables into a report. What I want to do is at the push of a button, refresh the query, copy the report into a new workbook, save that workbook in a specific location, and return the cursor to cell A1 in the original workbook.
So far I have created a form control button, recorded a macro that does everything as described above and also deletes the button on the new workbook, and assigned the macro to the button. When I run it everything works as needed; however, the button on the original file duplicates itself, and when I open the newly created file, the original button is gone, but the duplicated button now appears.
Does anyone know why this might be the case and what I can do about it? Here is the code from my Macro if it helps.......
Sub Macro1()
'
' Macro1 Macro
'
'
Range("B2").Select
Sheets("Query").Select
ActiveSheet.Buttons.Add(939, 52.5, 105, 47.25).Select
Sheets("Query").Copy
ActiveSheet.Shapes.Range(Array("Button 1")).Select
Selection.Delete
ActiveWindow.SmallScroll Down:=-9
ChDir "F:"
ActiveWorkbook.SaveAs Filename:="F:\Test.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
Range("Test_Data_2[[#Headers],[Transaction ID]]").Select
End Sub
Thanks in Advance,
Jonathan