How can I copy the names in a List1Box to a new notepad.txt document?
Also can I do this same thing with a File1 list box?
Thanks,
JO
Printable View
How can I copy the names in a List1Box to a new notepad.txt document?
Also can I do this same thing with a File1 list box?
Thanks,
JO
Try this:
Same goes for a FileListBox.Code:AppActivate "Untitled - Notepad"
For i = 0 to List1.ListCount - 1
SendKeys List1.List(i)
SendKeys "{ENTER"}
DoEvents
Next i
Code:AppActivate "Untitled - Notepad"
For i = 0 to File1.ListCount - 1
SendKeys File1.List(i)
SendKeys "{ENTER"}
DoEvents
Next i
I'm getting Run-time error 5
Invalid procedure call or arguement
for AppActivate ("Untitled - Notepad")
Any idea why this may be happening?
JO
instead use
shell path\notepad.exe,vbNormalFocus
This says "Object required"
for shell path\notepad.exe,vbNormalFocus
JO
replace path with your notepad path:
exemple:c:\windows\notepad.exe
replace "path" with correct path
such as "c:\windows\notepad.exe"
Got It!
thank you
JO
This works but it opens Notepad 2 times and writes the info in the second one.
Private Sub Command2_Click()
Shell "C:\WINNT4\Notepad.exe"
For i = 0 To File1.ListCount - 1
SendKeys File1.List(i)
SendKeys "{ENTER}"
DoEvents
Next
End Sub
change it to
Code:Private Sub Command2_Click()
Shell "C:\WINNT4\Notepad.exe",vbNormalFocus
For i = 0 To File1.ListCount - 1
SendKeys File1.List(i)
SendKeys "{ENTER}"
DoEvents
Next
End Sub
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal opOperation As String, ByVal lpFile As String, ByVal opParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
' just call it like this ShellExe("Explorer")
Public Sub ShellExe(What As String)
On Error Resume Next
Call ShellExecute(0&, vbNullString, What, vbNullString, vbNullString, vbNormalFocus)
End Sub
Private Sub Command1_Click()
ShellExe "notepad.exe"
AppActivate "Untitled - Notepad"
For i = 0 To File1.ListCount - 1
SendKeys File1.List(i)
SendKeys "{ENTER}"
DoEvents
Next i
End Sub
Something else I need to know is:
I'm trying to get a file name from the click event of a File1 Box when I click on the file name.
D:\MyFile\ "the name selected in the File1 box"
What is the syntax or property for the File1
I hope that is clear enough.
Thanks,
JO
FileName = File1.path & "\" & file1.filename
Try using the FindWindow api function with the code I posted instead.
Replace this code with the AppActivate one.Code:Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Usage
hWin = FindWindow("notepad", vbNullString)
Something else I'm trying to do is not working.
From the click event of my File1 box I'm trying to click a file name and have it copied or moved to another directory. When I use this:
Private Sub File1_DblClick()
Dim oFSO As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
Call oFSO.CopyFile(File1.Path & " \ " & File1.FileName, File2.Path & " \ " & File1.FileName)
Set oFSO = Nothing
End Sub
It doesn't work because their is no destination with that name (File2.Path & " \ " & File1.FileName)
Any ideas on how I can do this?
Thanks,
JO
Use a DirListBox along with the FileListBox.
And using FSO is your choice. You could just use the basic VB FileCopy function if you want.
Code:Private Sub File1_DblClick()
FileCopy Dir1.Path & "\" & File1.FileName, Dir2.Path & _
"\" & File1.FileName)
End Sub
also make sure that if you source or destination is,
c:\ don't do:
source & "\" & filename cuz the result :
c:\\text.txt
Hey what other basic VB File functions are there besides FileCopy:
Like FileMove or FileSomething?
I didn't even know there was a FileCopy function.
Of course I'm self teaching.
Thanks a bunch
JO
As sebs said, if the file is in C:\, you will get C:\\.
Here is how you can determine which is which.
VB doesn't have a function where you can move files. Only a FileCopy function. In this case, you can use FSO :).Code:Private Sub File1_DblClick()
If Len(Dir1.Path) <= 3 Then CDir$ = Dir1.Path & _
File1.Filename
If Len(Dir1.Path) > 3 Then CDir$ = Dir1.Path & "\" & _
File1.Filename
If Len(Dir1.Path) <= 3 Then CDir2$ = Dir2.Path & _
File1.Filename
If Len(Dir1.Path) > 3 Then CDir2$ = Dir2.Path & "\" & _
File1.Filename
FileCopy CDir$, CDir2$
End Sub
Code:Private Sub File1_DblClick()
Dim FSO as Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.MoveFile FromFile1, ToFile2
End Sub
Hey Matthew, now don't start to lie huh? ;)
It does have a Move function, but it has a strange name:Quote:
VB doesn't have a function where you can move files. Only a FileCopy function. In this case, you can use FSO .
NAME :)
that'll move oldfile.fl from c:\jop\ to c:\jop\otherdirCode:Name "c:\jop\oldfile.fl" As "c:\jop\otherdir\oldfile.fl"
hope that cleared some things up for ya :)
Oh before I forget, you can also rename files :)
Code:Name "c:\jop\oldfile.fl" As "c:\jop\newfile.fl"
Thanks so much!!
This has gotten me out of a bit of a bind.
JO
I knew that Jop, I was just testing you :rolleyes:.
lol, good one Matthew!!! :pQuote:
I knew that Jop, I was just testing you .