PDA

View Full Version : Document select, and move



Widerebel
11-04-2014, 10:16 AM
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)

Bob Phillips
11-04-2014, 12:28 PM
Try this


With Application.FileDialog(msoFileDialogOpen)

.AllowMultiSelect = False
If .Show = -1 Then

OldFilename = .SelectedItems(1)
Name OldFilename As NewFilename
End If
End With

Bob Phillips
11-04-2014, 12:28 PM
Try this


With Application.FileDialog(msoFileDialogOpen)

.AllowMultiSelect = False
If .Show = -1 Then

OldFilename = .SelectedItems(1)
Name OldFilename As NewFilename
End If
End With

Widerebel
11-05-2014, 12:50 AM
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 :)

Bob Phillips
11-05-2014, 01:13 AM
SelectedFile = Application.GetOpenFilename("PDF Files (*.pdf), *.pdf")

Widerebel
11-05-2014, 04:16 AM
SelectedFile = Application.GetOpenFilename("PDF Files (*.pdf), *.pdf")

Thank you sir for the help. I got it working :)