|
LITTLEBLACKDOG.COM
|
| Author |
Message |
squashman
Big Dog


Joined: 08 Oct 2001 Posts: 3471
Location: 1265 Lombardi Ave.
|
Posted:
Thu May 15, 2008 7:12 pm Post subject: Excel Macro |
|
Is it possible to have a Macro output the contents of the currently selected Cell to a text file? |
|
|
|
|
|
|
EdisonRex
Lead Dog


Joined: 06 May 2002 Posts: 10046
Location: Not Moscow
|
Posted:
Fri May 16, 2008 12:33 am Post subject: |
|
The short answer is "of course".
Code to do this would be something like
Dim Outfile, OutStr As String
Open Outfile For Output As #1
OutStr = ActiveCell.Value ' you might need to convert to string
Print #1, OutStr |
_________________ Garret: It's so retro.
EGM: What does retro mean to you?
Parker: Like, old and outdated.
|
|
|
|
|
squashman
Big Dog


Joined: 08 Oct 2001 Posts: 3471
Location: 1265 Lombardi Ave.
|
Posted:
Wed Jun 04, 2008 9:31 am Post subject: |
|
This is what I ended up doing.
Sub SendCellToTextFile2()
Dim sFullName As String, sPath As String, iFileNum As Integer, iReply As Integer
If Intersect(ActiveCell, Range("A:D")) Is Nothing Then
MsgBox "You must select a cell in A or D!", vbExclamation, "ERROR!"
Exit Sub
End If
If Cells(ActiveCell.Row, "D").Value = vbNullString Or Cells(ActiveCell.Row, "B").Value = vbNullString Or Cells(ActiveCell.Row, "A").Value = vbNullString Then
MsgBox "You need to fill out both cells!", vbExclamation, "ERROR!"
Exit Sub
End If
sPath = ThisWorkbook.Path & "\batch\"
If Dir(sPath, vbDirectory) = "" Then MkDir sPath
sFullName = sPath & "String_" & Cells(ActiveCell.Row, "A").Value & ".bat"
iFileNum = FreeFile
Open sFullName For Output Access Write As #iFileNum
Print #iFileNum, Cells(ActiveCell.Row, "D").Value
Close #iFileNum
iReply = MsgBox(Prompt:="Do you wish to run String_" & Cells(ActiveCell.Row, "A").Value & ".bat", _
Buttons:=vbYesNo, Title:="Run Batch File")
If iReply = vbYes Then
Shell sFullName 'Run the batch file
Else 'They clicked No
Exit Sub
End If
End Sub |
|
|
|
|
|
|
|
|
|
|
View next topic
View previous topic
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB
© 2001, 2002 phpBB Group
phpBB SEO
All times are GMT - 8 Hours
Help us keep advertisements off this site. Donate today!
|
|