PDA

View Full Version : control wordpad from Excel using VBA



Kristoffer J
03-28-2012, 02:02 AM
hey

thi is what i have ..

ThisWorkbook.Worksheets(1).Cells(1, 1).Select
Selection.Copy
Call Shell("NOTEPAD.EXE C:\Documents and Settings\ik01log\HODObjs\Prove 1.txt", 1)
SendKeys "^{V}"

The above works, however:
1) Instead of selecting a cell and copy paste I would like to paste information from a string variable into the text document.
2) I would like to save the txt-file automatically afterwards

Aflatoon
03-28-2012, 04:07 AM
No need to automate a program for that:

Sub WriteText(strFile As String, strText As String)
Dim filenum As Integer
filenum = FreeFile
Open strFile For Append As filenum
Print #filenum, strText
Close #filenum
End Sub


called with:

WriteText "C:\Documents and Settings\ik01log\HODObjs\Prove 1.txt", ThisWorkbook.Worksheets(1).Cells(1, 1).Value

Kristoffer J
03-28-2012, 04:13 AM
:hi: i will look in to that one...

Kristoffer J
03-28-2012, 06:13 AM
Thanks for the help!

I made my code print a string into a text file by doing this:

Open "C:\Documents and Settings\ik01log\HODObjs\inuk9.txt" For Append As #1
Print #1, myString
Close #1

What I would like to do now is to 1) either delete some lines or 2) delete everything in the file before printing the string into it.

Is this possible?

Aflatoon
03-28-2012, 06:20 AM
Replace the word 'Append' with 'Output' to overwrite the file.

Note: if you are going to keep cross-posting, it would be courteous to provide links to the other posts to save spending time on already solved problems.

Kristoffer J
04-04-2012, 12:08 AM
cool i will try that.

i don't know what you mean by cross-posting. i only have this post. but i am new her so the might be something that i am not aware of.


Kris





Replace the word 'Append' with 'Output' to overwrite the file.

Note: if you are going to keep cross-posting, it would be courteous to provide links to the other posts to save spending time on already solved problems.

Aflatoon
04-04-2012, 12:23 AM
Cross-posting is when you post the same question on multiple web sites. For example, I know you got the code you posted on another site. When you cross post without saying so, we can end up wasting time providing code when you already have an answer elsewhere.

Kristoffer J
04-04-2012, 12:27 AM
okay like that, it did not accuracy to me, but yes i did so, will keep that in mind, from now on..




Cross-posting is when you post the same question on multiple web sites. For example, I know you got the code you posted on another site. When you cross post without saying so, we can end up wasting time providing code when you already have an answer elsewhere.