Results 1 to 20 of 20

Thread: Open DXF file from a button on the toolbar or userform is not working, Need help?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,884
    Location
    Quote Originally Posted by Johnnydotcom View Post
    Paul, thanks for going into that much detail, here's the money shot on this code.

    The CurVal, ie Current Value, is the selection in a Large spreadshseet containing bills of material part numbers, such as 1717-803-12-1

    the DXF file that the program is looking for start with 1717-803-12-1, however, also contains data such as a space and the letters REV1, so the file names part number is 1717-803-12-1 REV1, however, this could also be 1717-803-12-1-REV1 or 1717-803-12-1 - REV1.

    so as you can see there is a variation.

    the \* * combats this problem very well.
    Unsolicited suggestions:

    1. I'd not rely on ActiveCell for anything

    2. The Dir() will find the first DFX file in pth which might be OK (or not)

    Option Explicit
    
    
    'The CurVal, ie Current Value, is the selection in a Large spreadshseet containing bills of material part numbers, such as 1717-803-12-1
    'the DXF file that the program is looking for start with 1717-803-12-1, however, also contains data such as a space and the letters REV1,
    '   so the file names part number is 1717-803-12-1 REV1, however, this could also be 1717-803-12-1-REV1 or 1717-803-12-1 - REV1.
    'so as you can see there is a variation.
    
    
    Sub Open_TXT()
        Dim pth As String, fName As String, CurVal As String
        
        CurVal = ActiveCell.Value
        
        CurVal = Range("A1")  '   <<<<<<<<<<<<<<<<<<<<<<<<<<<<< for testing
        
        pth = Range("H3").Value
        If Right(pth, 1) <> Application.PathSeparator Then pth = pth & Application.PathSeparator
        
        fName = Dir(pth & CurVal & ".txt")  '   <<<<<<<<<<<<<<<<<<<<<<<<<<<<< for testing
            
        If fName = "" Then
            ChDrive Left(pth, 2)
            ChDir pth
            fName = Application.GetOpenFilename("DFX Files (*.txt), *.txt")
            If fName = "False" Then Exit Sub
        
            ActiveWorkbook.FollowHyperlink fName
            
        Else
            ActiveWorkbook.FollowHyperlink pth & fName
        End If
    End Sub
    Last edited by Paul_Hossler; 04-05-2024 at 06:36 AM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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