Results 1 to 4 of 4

To have flexibility to open workbook file on a specific drive\subfolder.

Threaded View

  1. #1
    Registered User
    Join Date
    06-08-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2016
    Posts
    6

    Smile To have flexibility to open workbook file on a specific drive\subfolder.

    Hi Expert,

    I was new on VB scrip, my understanding on the below function use are not that good.

    I have one excel file (A) that has macro button to open up another excel file (B) at the same subfolder location with the below function.

    ========================
    Function MyDocuments() As String
        Dim objFSO As Object
        Dim objShell As Object
        Dim objFolder As Object
        Dim objFolderItem As Object
        
        Const MY_DOCUMENTS = &H5&
        
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objShell = CreateObject("Shell.Application")
        
        Set objFolder = objShell.Namespace(MY_DOCUMENTS)
        Set objFolderItem = objFolder.Self
        MyDocuments = objFolderItem.Path
        
    End Function
    
    
    Function Open_File()
        Dim Path As String
        Path = MyDocuments() & "\Sales Tools\Quotation Form.xls"
        Set Quotation = Workbooks.Add(Path).ActiveSheet
        Set Calculation = ThisWorkbook.ActiveSheet
        
    End Function
    ==================================

    Query 1 : What does it mean on "Const MY_DOCUMENTS = &H5&" ?
    Query 2 : is that possible to change the path to be more specific as fixed it at c drive\ subfolder? What changes i should make on the function above?
    Query 3 : is that possble to change the path to flexible where user paste the folder at desktop or other drive on above statement?
    Query 4 : I keep having problem on running above function which doesn't recognised the excel file (B) to be open. How do I refresh the path variable?

    query 5 : For excel file A & B are sitting at the same subfolder, how do i get the macro button to automatic call search file from the same subfolder and with the filename as "Quotation Form.xls"

    hope to hear the expert.

    Thanks

    Regards,
    Anney Png
    Last edited by FDibbins; 10-02-2012 at 02:15 AM.

Thread Information

Users Browsing this Thread

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

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