Hi,
I'm quite new to using VBA, and already very enthusiastic! I am trying to create a macro where I am able import sheets from other workbooks automatically into my workbook. I have managed to do so with the following macro:
Sub import()
Dim wbCopy As Workbook
Dim wsCopy As Worksheet
Dim rngCopy As Range
Dim wbPaste As Workbook
Dim wsPaste As Worksheet
Dim rngPaste As Range
Dim Pivot As PivotTable
Set wbCopy = Workbooks.Open("X:\...\2016\2016-04\importfile.csv")
Set wsCopy = wbCopy.Worksheets("import")
Set rngCopy = wsCopy.Range("a:xfd").EntireColumn
Set wbPaste = Workbooks("myfile.xlsm")
Set wsPaste = wbPaste.Worksheets("import")
Set rngPaste = wsPaste.Range("a1")
rngCopy.Copy
rngPaste.PasteSpecial
Workbooks.Application.CutCopyMode = False
Workbooks("importfile.csv").Close False
Range("V3") = "x"
Range("Y3") = "xx"
ActiveWorkbook.RefreshAll
End Sub
My question is: How do I make a dynamic formula in such a way that for example when in month no. 5, the macro knows it has to search in folder "2016-04" and so on? And in a file named for example "importfile 2016-04.xlsx".
I hope my question is clear, if not: please let me know so I can better specify.
Thanks
I'm quite new to using VBA, and already very enthusiastic! I am trying to create a macro where I am able import sheets from other workbooks automatically into my workbook. I have managed to do so with the following macro:
Sub import()
Dim wbCopy As Workbook
Dim wsCopy As Worksheet
Dim rngCopy As Range
Dim wbPaste As Workbook
Dim wsPaste As Worksheet
Dim rngPaste As Range
Dim Pivot As PivotTable
Set wbCopy = Workbooks.Open("X:\...\2016\2016-04\importfile.csv")
Set wsCopy = wbCopy.Worksheets("import")
Set rngCopy = wsCopy.Range("a:xfd").EntireColumn
Set wbPaste = Workbooks("myfile.xlsm")
Set wsPaste = wbPaste.Worksheets("import")
Set rngPaste = wsPaste.Range("a1")
rngCopy.Copy
rngPaste.PasteSpecial
Workbooks.Application.CutCopyMode = False
Workbooks("importfile.csv").Close False
Range("V3") = "x"
Range("Y3") = "xx"
ActiveWorkbook.RefreshAll
End Sub
My question is: How do I make a dynamic formula in such a way that for example when in month no. 5, the macro knows it has to search in folder "2016-04" and so on? And in a file named for example "importfile 2016-04.xlsx".
I hope my question is clear, if not: please let me know so I can better specify.
Thanks