Results 1 to 3 of 3

Using VBA how do you close a user defind workbook after you have extracted data

Threaded View

  1. #1
    Registered User
    Join Date
    11-14-2012
    Location
    Lebanon, Oregon
    MS-Off Ver
    Excel 2010
    Posts
    47

    Using VBA how do you close a user defind workbook after you have extracted data

    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
    Last edited by klonbeck; 11-14-2012 at 06:02 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1