Hi all,
I'm very new to VBA, up to now I've mainly been creating macros within Excels tools. I should probably point out that I'm using Office 365 on a Mac (which has thrown up some issues before!)
So far I've have managed to;
- Open a .txt file thats path and name will always be the same (luckily!) and import to a new workbook
- Copy columns (A:J)
- Then I want to swap to the workbook that the macro was trigged from without specifying a path as this will be different almost every time
- Paste that data in sheet 'VW Import' in (A1)
- Close the workbook the data was copied from.
Any guidance is much appreciated, as I said I'm very new to this, so forgive any bizarre coding.
THank
I'm very new to VBA, up to now I've mainly been creating macros within Excels tools. I should probably point out that I'm using Office 365 on a Mac (which has thrown up some issues before!)
So far I've have managed to;
- Open a .txt file thats path and name will always be the same (luckily!) and import to a new workbook
- Copy columns (A:J)
- Then I want to swap to the workbook that the macro was trigged from without specifying a path as this will be different almost every time
- Paste that data in sheet 'VW Import' in (A1)
- Close the workbook the data was copied from.
VBA Code:
Sub ImportData()
'
' ImportData Macro
'
Workbooks.OpenText FileName:= _
"/Users/dan/Library/Group Containers/UBF8T346G9.Office/ExcelExport/VWExport", _
Origin:=xlMacintosh, StartRow:=1, DataType:=xlDelimited, TextQualifier _
:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:= _
False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array _
(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1)), TrailingMinusNumbers:= _
True
Columns("A:J").Select
Selection.Copy
'This is where I need to call back to my open workbook I'd like the data pasted into. The worksheet will already be open as the Macro will be activated.
Range("A1").Select
ActiveSheet.Paste
ActiveWindow.Close
End Sub
Any guidance is much appreciated, as I said I'm very new to this, so forgive any bizarre coding.
THank