Consulting

Results 1 to 6 of 6

Thread: Document select, and move

  1. #1

    Document select, and move

    Dear user,

    I have a question regarding excel VBA. I'm busy with a form where you can ad an document to an database.
    But i can't solve it myself,so therefore i'm asking here.

    The problem:
    I want to select a document from a folder, with the folder browser. Then if you select it, i wan't that it gonna be moved to a folder that i'm generating with a variable and some static text.
    Select document from a folder -> move document to another folder (generated by a variable) -> Give the document a different name (also with a variable) / this is gonna be done, when you hit complete and everything else is filled in.
    The file can be .PDF or some other extensions. this is being generated by an drop down button

    Anyway, if you guys need more information. pleas ask.
    I am grateful for your help!

    Kind Regard,
    Widerebel
    Sjors
    (Sorry for the bad grammar, i did my best)

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

        With Application.FileDialog(msoFileDialogOpen)
        
            .AllowMultiSelect = False
            If .Show = -1 Then
            
                OldFilename = .SelectedItems(1)
                Name OldFilename As NewFilename
            End If
        End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

        With Application.FileDialog(msoFileDialogOpen)
        
            .AllowMultiSelect = False
            If .Show = -1 Then
            
                OldFilename = .SelectedItems(1)
                Name OldFilename As NewFilename
            End If
        End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Quote Originally Posted by xld View Post
    Try this

        With Application.FileDialog(msoFileDialogOpen)
        
            .AllowMultiSelect = False
            If .Show = -1 Then
            
                OldFilename = .SelectedItems(1)
                Name OldFilename As NewFilename
            End If
        End With
    Dear xld,

    Thank you for the answer. I just managed to get it with another code.

    Sub MoveFile()  Dim NewPath As String, NewFilename As String, SelectedFile As String
      NewPath = "D:\temp\"  'Note the trailing backslash
      NewFilename = "NewName2"
      SelectedFile = Application.GetOpenFilename
      If SelectedFile <> "False" Then
         NewFilename = NewPath & NewFilename & Mid(SelectedFile, InStrRev(SelectedFile, "."))
         Name SelectedFile As NewFilename
      End If
    End Sub
    For the people that are interested. I only have one guestion remaining.
    How can i get the file extension? i want the extension being put in an textbox with the name "textbox2".
    and by the extension i mean, .PDF or .XLS and so on.

    Thank you

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    SelectedFile = Application.GetOpenFilename("PDF Files (*.pdf), *.pdf")
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Quote Originally Posted by xld View Post
    SelectedFile = Application.GetOpenFilename("PDF Files (*.pdf), *.pdf")
    Thank you sir for the help. I got it working

Posting Permissions

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