Hi All
I'm trying to create a form where you can generate a series of text
files that come from a spreadsheet. The spreadsheet has 7 columns and
each text file should have 7 entries in it (a single record/row). The
spreadsheet looks like:
Name Value 1 Value 2 Value 3 Value 4 Value 5 Value 6
With the code I have I want the text files to have the format:
Value 1
Value 2
Value 3
Value 4
Value 5
Value 6
The file will have the text from the name column as its filename.
However instead of the extension .txt for a text file I would like to
have the extensions .jgw and .jpw and .tfw.
The following code is
Private Sub cmdRange_Click()
Set myRng = Nothing
On Error Resume Next
Set myRng = Application.InputBox(prompt:=quot;Select a range with the
mousequot;, _
Type:=8)
On Error GoTo 0
If myRng Is Nothing Then
'use hit cancel
Exit Sub
End If
End Sub
Sub cmdGenerate_Click()
'Select worldfile type from option buttons
Select Case True
Case optJpeg.Value
Extension = quot;.jgwquot;
MsgBox quot;You've selected Jpegsquot;
Case optIllustrator.Value
Extension = quot;.jpwquot;
MsgBox quot;You've selected Illustrator filesquot;
Case optTif.Value
Extension = quot;.tfwquot;
MsgBox quot;You've selected Tif filesquot;
End Select
'Macro for creating world files
ChDir quot;C:\working_dataquot;
For Each myRng In Range (myRng)
If myRng.Value lt;gt; quot;quot; Then
FNum = FreeFile
Open myRng.Value amp; quot;Extensionquot; For Output Access Write As
#FNum
Print #FNum, myRng(1, 2).Value
Print #FNum, myRng(1, 3).Value
Print #FNum, myRng(1, 4).Value
Print #FNum, myRng(1, 5).Value
Print #FNum, myRng(1, 6).Value
Print #FNum, myRng(1, 7).Value
Close #FNum
End If
Next myRng
End Sub
The code seem okay for the most part but breaks down at
For Each myRng In Range (myRng)
If anybody has ideas out there it would be greatly appreciated.
Thanks,
MikeI didn't create the userform, but this may get you further along:
Option Explicit
Private Sub CommandButton1_Click()
Dim FileNum As Long
Dim myRng As Range
Dim myCell As Range
Dim myFolder As String
Dim Extension As String
Dim fNum As Long
Dim iCtr As Long
Set myRng = Nothing
On Error Resume Next
Set myRng = Application.InputBox(prompt:=quot;Select a range with the mousequot;, _
Type:=8)
On Error GoTo 0
If myRng Is Nothing Then
'user hit cancel
Exit Sub
End If
'assumes the name is in column A
Set myRng = myRng.EntireRow.Columns(1)
myFolder = quot;C:\working_dataquot;
If Right(myFolder, 1) lt;gt; quot;\quot; Then
myFolder = myFolder amp; quot;\quot;
End If
'for my testing only.
Extension = quot;.jgwquot;
' Select Case True
' Case optJpeg.Value
' Extension = quot;.jgwquot;
' MsgBox quot;You've selected Jpegsquot;
' Case optIllustrator.Value
' Extension = quot;.jpwquot;
' MsgBox quot;You've selected Illustrator filesquot;
' Case optTif.Value
' Extension = quot;.tfwquot;
' MsgBox quot;You've selected Tif filesquot;
' End Select
For Each myCell In myRng.Cells
If myCell.Value lt;gt; quot;quot; Then
fNum = FreeFile
Close #fNum
Open myFolder amp; myCell.Value amp; Extension For Output As #fNum
For iCtr = 1 To 6
Print #fNum, myCell.Offset(0, iCtr).Value
Next iCtr
Close #fNum
End If
Next myCell
End Sub
Greshter wrote:
gt;
gt; Hi All
gt;
gt; I'm trying to create a form where you can generate a series of text
gt; files that come from a spreadsheet. The spreadsheet has 7 columns and
gt; each text file should have 7 entries in it (a single record/row). The
gt; spreadsheet looks like:
gt;
gt; Name Value 1 Value 2 Value 3 Value 4 Value 5 Value 6
gt;
gt; With the code I have I want the text files to have the format:
gt;
gt; Value 1
gt; Value 2
gt; Value 3
gt; Value 4
gt; Value 5
gt; Value 6
gt;
gt; The file will have the text from the name column as its filename.
gt; However instead of the extension .txt for a text file I would like to
gt; have the extensions .jgw and .jpw and .tfw.
gt;
gt; The following code is
gt;
gt; Private Sub cmdRange_Click()
gt;
gt; Set myRng = Nothing
gt; On Error Resume Next
gt; Set myRng = Application.InputBox(prompt:=quot;Select a range with the
gt; mousequot;, _
gt; Type:=8)
gt; On Error GoTo 0
gt;
gt; If myRng Is Nothing Then
gt; 'use hit cancel
gt; Exit Sub
gt; End If
gt;
gt; End Sub
gt;
gt; Sub cmdGenerate_Click()
gt;
gt; 'Select worldfile type from option buttons
gt;
gt; Select Case True
gt; Case optJpeg.Value
gt; Extension = quot;.jgwquot;
gt; MsgBox quot;You've selected Jpegsquot;
gt; Case optIllustrator.Value
gt; Extension = quot;.jpwquot;
gt; MsgBox quot;You've selected Illustrator filesquot;
gt; Case optTif.Value
gt; Extension = quot;.tfwquot;
gt; MsgBox quot;You've selected Tif filesquot;
gt; End Select
gt;
gt; 'Macro for creating world files
gt;
gt; ChDir quot;C:\working_dataquot;
gt;
gt; For Each myRng In Range (myRng)
gt; If myRng.Value lt;gt; quot;quot; Then
gt; FNum = FreeFile
gt; Open myRng.Value amp; quot;Extensionquot; For Output Access Write As
gt; #FNum
gt; Print #FNum, myRng(1, 2).Value
gt; Print #FNum, myRng(1, 3).Value
gt; Print #FNum, myRng(1, 4).Value
gt; Print #FNum, myRng(1, 5).Value
gt; Print #FNum, myRng(1, 6).Value
gt; Print #FNum, myRng(1, 7).Value
gt; Close #FNum
gt; End If
gt; Next myRng
gt; End Sub
gt;
gt; The code seem okay for the most part but breaks down at
gt;
gt; For Each myRng In Range (myRng)
gt;
gt; If anybody has ideas out there it would be greatly appreciated.
gt;
gt; Thanks,
gt; Mike
--
Dave Peterson
Dave
You've done it again - just what I'm after. A few tweaks that I can do
but aside from that it's given me a nice little user form.
Thanks very much
p.s - anyplace that you want me to write a little commendation or
something to that effect ... I think you deserve itGlad you have it working. And thanks for the offer.
Greshter wrote:
gt;
gt; Dave
gt;
gt; You've done it again - just what I'm after. A few tweaks that I can do
gt; but aside from that it's given me a nice little user form.
gt;
gt; Thanks very much
gt;
gt; p.s - anyplace that you want me to write a little commendation or
gt; something to that effect ... I think you deserve it
--
Dave Peterson
- Aug 14 Mon 2006 20:08
Code error in creating text files
close
全站熱搜
留言列表
發表留言