Suvster
New Member
- Joined
- Jul 28, 2017
- Messages
- 2
Hi all,
I'm fairly new to VBA and have been trying to muddle together a VBA macro to basically select a predefined folder, open any workbooks within that folder (ideally, i wouldn't even open the workbooks if possible but thought this would be far to complex for me starting out) and copy and paste the contents of specified worksheets (identified in an array) as values.
Below is what i've managed from taking bits here and there online.
The requirement was to make certain tables static rather than dynamic as we are linking to them with another application and the dynamic text doesn't link through.
I've gone through quite a few variations of this code but this seemed to be the closest i got to one actually working and i feel like it just needs a more experienced mind to tweak it.
I'm sure there are many things i could do to improve this but my first priority was to just get it to work.
Any help is appreciated.
I'm fairly new to VBA and have been trying to muddle together a VBA macro to basically select a predefined folder, open any workbooks within that folder (ideally, i wouldn't even open the workbooks if possible but thought this would be far to complex for me starting out) and copy and paste the contents of specified worksheets (identified in an array) as values.
Below is what i've managed from taking bits here and there online.
The requirement was to make certain tables static rather than dynamic as we are linking to them with another application and the dynamic text doesn't link through.
I've gone through quite a few variations of this code but this seemed to be the closest i got to one actually working and i feel like it just needs a more experienced mind to tweak it.
I'm sure there are many things i could do to improve this but my first priority was to just get it to work.
Any help is appreciated.
Code:
Sub version2()
Dim MyPath As String
Dim MyFile As String
Dim Wkb As Workbook
Dim Cnt As Long
Dim Assets As Variant
Dim Asset As Variant
Assets = Array("Geogr_segments", "Options_2", "PPE_short")
Application.ScreenUpdating = False
MyPath = ThisWorkbook.Path & "\Convert\" 'change the path accordingly
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
MyFile = Dir(MyPath & "*.xlsx")
Cnt = 0
Do While Len(MyFile) > 0
Cnt = Cnt + 1
Set Wkb = Workbooks.Open(MyPath & MyFile)
For Each Asset In Assets
'my code here
Wkb.Worksheets(Asset).Select
Range("F17").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next Asset
Wkb.Close savechanges:=True
MyFile = Dir
Loop
If Cnt > 0 Then
MsgBox "Completed...", vbExclamation
Else
MsgBox "No files were found!", vbExclamation
End If
Application.ScreenUpdating = True
End Sub