I have created a button call that lets the user select the desired xls file. The command then opens the file and takes data from column B and does a paste special (transpose) into the orignal workbook (Drawing Redlines.xls). The problem I am having is the user defind file will never have the same name. How do I setup the code to close the macro opend workbook once the data has been extracted?
If I define the file it works fine but the file name will never be the same hence the problem.
These are some sample files
DRAWING REDLINES.xlsmDWGLST.xls
And here is the whole code as of now:
Sub Drawing_Name_Browse_Click()
'
' Drawing_Name_Browse_Click Macro
' User selects DWGLST.xls from project folder for redline chart
'
' Keyboard Shortcut:
'
' Drawing_Name_Browse_Click R00
' Created 11/14/2012 by KLON.
'
'
'
'
'''''Macro variables
Dim v As Variant
Dim oCell As Range
Dim oColumn As Range
'''''User selected file
InitialFoldr$ = "C:\Vault\Projects" '<<<<<<<<< Startup folder to begin searching from
With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select source file"
.InitialFileName = InitialFoldr$
.Show
v = .SelectedItems(1)
'''''Opens user selected file
Workbooks.Open Filename:=v
End With
'''''Copies cell data from Column "FILENAME"
Range("B2:B200").Select
Application.CutCopyMode = False
Selection.Copy
'''''Activates Drawing Redlines.xls
Windows("DRAWING REDLINES.xlsm").Activate
'''''Pastes "FILENAME" values and formats cells
Range("D2").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Application.CutCopyMode = False
'''''Sets text alignment to 90deg
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 90
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'''''Adds borders to cells
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
'''''Close DWGLST.xls
Workbooks("DWGLST.xls").Close
This is the part I am having problems with:
'''''Close DWGLST.xls
Workbooks("DWGLST.xls").Close
End Sub
Any help would be appreciated. I have been looking on this forum and others but I have not been able to find anything so I am posting my qquestion.
Thanks in advance
Bookmarks