Code error in creating text files

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:="Select a range with the
mouse", _
                  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 = ".jgw"
            MsgBox "You've selected Jpegs"
        Case optIllustrator.Value
            Extension = ".jpw"
            MsgBox "You've selected Illustrator files"
        Case optTif.Value
            Extension = ".tfw"
            MsgBox "You've selected Tif files"
    End Select

'Macro for creating world files

ChDir "C:\working_data"

    For Each myRng In Range (myRng)
        If myRng.Value <> "" Then
            FNum = FreeFile
            Open myRng.Value & "Extension" 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,
Mike

0
mike6672 (16)
1/13/2006 2:50:05 AM
excel.misc 78881 articles. 5 followers. Follow

3 Replies
272 Views

Similar Articles

[PageSpeed] 30

I 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:="Select a range with the mouse", _
                  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 = "C:\working_data"    
    If Right(myFolder, 1) <> "\" Then
        myFolder = myFolder & "\"
    End If
    
    'for my testing only.
    Extension = ".jgw"
    
'    Select Case True
'        Case optJpeg.Value
'            Extension = ".jgw"
'            MsgBox "You've selected Jpegs"
'        Case optIllustrator.Value
'            Extension = ".jpw"
'            MsgBox "You've selected Illustrator files"
'        Case optTif.Value
'            Extension = ".tfw"
'            MsgBox "You've selected Tif files"
'    End Select
    
    For Each myCell In myRng.Cells
        If myCell.Value <> "" Then
            fNum = FreeFile
            Close #fNum
            Open myFolder & myCell.Value & 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:
> 
> 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:="Select a range with the
> mouse", _
>                   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 = ".jgw"
>             MsgBox "You've selected Jpegs"
>         Case optIllustrator.Value
>             Extension = ".jpw"
>             MsgBox "You've selected Illustrator files"
>         Case optTif.Value
>             Extension = ".tfw"
>             MsgBox "You've selected Tif files"
>     End Select
> 
> 'Macro for creating world files
> 
> ChDir "C:\working_data"
> 
>     For Each myRng In Range (myRng)
>         If myRng.Value <> "" Then
>             FNum = FreeFile
>             Open myRng.Value & "Extension" 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,
> Mike

-- 

Dave Peterson
0
petersod (12004)
1/13/2006 3:12:48 PM
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 it

0
mike6672 (16)
1/15/2006 9:23:20 PM
Glad you have it working.  And thanks for the offer.

Greshter wrote:
> 
> 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 it

-- 

Dave Peterson
0
petersod (12004)
1/15/2006 9:34:10 PM
Reply:

Similar Artilces:

Error number: 0x800ccc0e
Why am I getting this right after installing Outlook 2000? It was a gift. I have had no success trying to get info from the knowledge base. Nothing has changed except installing Office 2000. I configured everything just as I had previous. Going back to Outlook Express I get the same error. What is going on? Same story here. And I would love to just be able to go back to OE at this point. Darla >-----Original Message----- >Why am I getting this right after installing Outlook 2000? >It was a gift. I have had no success trying to get info >from the knowledge base. Nothing ...

how do I automatically update a text box in a chart?
Hi, You can link the textbox to a cell. When you update the cell the textbox should reflect this. Select the textbox border and then in the formula bar enter the complete cell reference, for example, =Sheet1!A1 Cheers Andy Kath wrote: -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info ...

data input in text box
We have a form which the operator enters data in a text box. Currently we have a 'done' button on the form that the operator clicks to send the text box info to a vba program. How can we send the text box info to the vba program when the operator hits the enter key @ the end of the data entry for the text box? TIA -- _______________________________ In Christ's matchless name ted & colleen n6trf kc6rue Use the control's AfterUpdate event. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "ted" <n6trf@arr...

Create a distribution list from addresses in the 'To' list
Hi all, I belong to a social group, and our co-ordinator sends out an email from time to time with all the latest addresses in the To list. I already have a distribution list for the group, which then needs to be checked through and updated. Is there a simple way of transferring those addresses into my own distribution list? I'm using Outlook 2002. Everybody's fiddling around with bits of paper - I'll be a hero if I can make it easy for them! Thanks. Astley http://www.outlook-tips.net/archives/2004/20041105.htm -- Russ Valentine [MVP-Outlook] "Astley" <ast@...

Error: Invalid byte was found at byte index 63.
Does anyone know what this means: "Invalid byte was found at byte index 63. " If yes, please help. Apogee Apogee wrote: > Does anyone know what this means: > > "Invalid byte was found at byte index 63. " That means exactly what it says: At index 63 XML parser found a byte, which is invalid either according document's encoding or is forbidden in XML documents at all (see list of allowed in XML characters at http://www.w3.org/TR/2000/REC-xml-20001006#charsets) -- Oleg Tkachenko http://www.tkachenko.com/blog Multiconn Technologies, Israel ...

Error Generating the Offlice Address Book
I have a mixed site with 3 5.5 server and 4 2003 servers. I installed 2003 SP1 a few weeks back and since then I'm having an issue generating my Offline Address Book. Here the event log messages I'm getting. Event ID 9331: OALGen encountered error 80040107 (internal ID 501023d) accessing the public folder store while generating the offline address list for address list '/'. - Default Offline Address List For more information, click http://www.microsoft.com/contentredirect.asp. Event ID 9335: OALGen encountered error 80040107 while cleaning the offline address list public ...

XCH Error 3092, OAB replication
I am getting error 3092 for OAB in Exchnage 2003 (migrated from 5.5) "Error 1129 occurred while processing a replication event. Folder: (3-8) NON_IPM_SUBTREE\OFFLINE ADDRESS BOOK\EX:/o" Tried to delete offilne addressbook and recreate but error has not stopped. Any help will be a great help on where to look to get rid of this issue. Thanks ...

MS Money 95 data files
I hope that some one can answer this for me. I have used MS Money 95 for years, and it works just fine for me on Windows XP, however, I now have to reformat my hard drive, and have discovered that I can nolonger find my original install disk. Will the latest versions of Money still read the MS Money 95 data files. All that I have ever used the program for is to track my investments, and am unlikely to do any different in the future. Thanks Stan B In microsoft.public.money, Stan Banner wrote: >I hope that some one can answer this for me. >I have used MS Money 95 for years, and...

Invalid XML error when I open customization setting
I have a problem when I try to open customization setting after I import an entity. The system errored "Invalid XML" "The XML passed to the platform is not well-formed XML". Please recommend how to resolve this problem. Thanks. ...

Where is the workspace file stored?
I was given a project folder containing several dozen files. So where is the workspace file normally located? If I don't have a workspace file how can I cerate one? Using VC version 6. TIA I haven't used VC6 for some time, but if I remember right you can just open the .dsp file and it will create a .dsw file for you. It typically goes in the same folder with the code. Tom "Phisherman" <noone@nobody.com> wrote in message news:be93539ccf8a6f25ibh4vt6ggmtbi024mq@4ax.com... >I was given a project folder containing several dozen files. So where > is the wor...

How do I create several NEW templates from start to finish please?
Hi knowledgeable people. I am looking for instructions on how to create a range of basic templates that I can use, perhaps even by selecting them as 'stationery', for example; if I go to >New >Format >Apply stationery, or any other similar method. I can create new html stationery backgrounds, but this is NOT what I am looking for, as a lot of people still read email in plain text only...does this make sense? Plain text templates would be fine. I simply can't find any info on creating email templates anywhere to suit this Windows Live Mail Desktop versio...

Linker Error after upgrade from VC7.1
Hello all, After upgrading a VC7.1 project to visual studio 2005, it failed to build in the release configuration with the follwoing error : 1>nafxcw.lib(winocc.obj) : error LNK2005: "public: class CWnd * __thiscall CWnd::GetDlgItem(int)const " (?GetDlgItem@CWnd@@QBEPAV1@H@Z) already defined in InstallDlg.obj The debug build works fine. The project uses MFC in a static library. Well, after doing some research, it seems that this one is tied to the fact that in a release configuration, _AFX_ENABLE_INLINES is defined, so inline functions are embedded in the .obj file. Sure there...

Unexpected error message on closing an Excel file
Suddenly I am getting the following message when I try to close a workbook: "Your formula contains an invalid external reference to a worksheet. Verify that the path, workbook, and range name or cell reference are correct, and try again" The mysterious thing is that it does not happen consistently and that, after I click OK after the above message, I can still save the file. What might be the cause of this error message and can the "invalid reference" be tracked down using one of the utility add-ins such as J. Walkenbach's PUP? If it only happens when you close ...

cant start outlook pst file to large
Hi I hope somebody may be able to help im new to outlook and now I cant start outlook message says cannot open your default email folders pst file its too large as I cannot open outlook I cannot delete old folders See if this helps: http://support.microsoft.com/kb/296088 -- -Ben- Ben M. Schorr, MVP Roland Schorr & Tower http://www.rolandschorr.com http://www.officeforlawyers.com/outlook.html Author: The Lawyer's Guide to Microsoft Outlook 2007: http://tinyurl.com/ol4law-amazon "Ray" <Ray@discussions.microsoft.com> wrote in message news:B3B824DC-3C9B-4B1B-8EF3-61...

Creating new attributes
When using Schema Manager to create new attributes, I'm not able to create a new attribute with "Lookup" as type, "Lookup" is not availabe as one of the type options. But yet some of the exist fields, for example, in Account table came with "Lookup" as type. Why? Is there a work-around? Please help. Thanks. You cannot add custom lookup's to the current release of MSCRM. The only way around is to build a custom .aspx page and build your own. Might be possible in the next release. "HEC" wrote: > When using Schema Manager to crea...

Change File Locations to Private Drive (not Folder)
Hi, I know that I can use "File Locations" in "Options" so that whenever I use the "Open..." command in Word, it will open to a specific folder. I'm wondering if there is a way that this can be applied not to a folder but to a specific drive on a network. Our company has a main public drive and has also assigned each of the Staff their own private drive. Is there a way to access the "main page" (for lack of a better term) of my private drive each time I use "Open..." in Word? Right now it goes to "My Computer" or ...

Adding Industry Codes
I am picking up the pieces on a previous installation of CRM, and want to add additional industries to my industry dropdown in the Lead form. For the life of me, I can't find the proper table in the database. Can someone be good enough to point me in the right direction? Thanks, Chris Chris, You don't do this via a table, you need to do it via form customization. You will need system admin rights, then go into System Customization and modify the Lead form. After making the changes, you will need to publish the change via Deployment Manager and issue an IISRESET. Matt "Chris...

adding name /creating field/query?
Hello, I can create an invoice_number field in a query using the primary field ID from the main table as invoice_number: ID but if ID say is 100, I cannot work out how to create renewal_invoice_100 Cheers Geoff Geoff We aren't there. We can't see what you're looking at. Where did "renewal_invoice_100" come from and what does it mean? Please post the SQL statement of the query you are trying to use. -- Regards Jeff Boyce www.InformationFutures.net Microsoft Office/Access MVP http://mvp.support.microsoft.com/ Microsoft IT Academy Program Mentor http://micro...

Drag and Drop file/directory names on Tree Control.
hi, I am writing an application in which i have one Tree control. Now i want that , when user drag & drop any file/folder on tree control the file name/folder name should be add in the tree control item. User may drag and drop file from desktop or may be from directory. I just want the path of that file/foder name nothing else. so plz tell me will it be possible ... Plz Help me............. Klic..... > I am writing an application in which i have one Tree control. >Now i want that , when user drag & drop any file/folder on tree >control the file nam...

Lookup text with multiple search criteria
I know how to look up data and text using vlookup and hlookup, what I' like to know is whether there is a way of looking up data based on mor than 1 search criteria; for example If I wanted to look up an item in a 4 column database, I'd us something like this: =VLOOKUP("Apples",A2:D10,4,false) But that only looks for Apples. Say I wanted to lookup data based on subcategory of Apples, e.g. colour. If it was a number, I could use SUMPRODUCT and (assuming named range were in use) do it like this: =SUMPRODUCT((Fruit="Apples)*(Colour="Red")*(Total)) But obvio...

Trying to read XML file into dataset
Hello. Developing a web site in VS2005, SP1, VB, .NET 2.0, ASP.NET 2.0 on XP Pro, SP2. I eventually want to use a gridview table to view xml data, but right now i can't seem to get my xml data into a dataset so that i can use it. I have an XML file and can open it in IE. There is no XSD or XSL file to go with it. I can't seem to get the XML data into a dataset. I tried using the following code, but it just does nothing. It doesn't give an error. It just executes the code and does nothing. Dim dataSet As DataSet = New DataSet dataSet.ReadXml("...

error on upgrade: ID 4386
Hello, I am upgrading from DPM 2010 RC to DPM 2010 RTM, 64 bit version, on Win 2008 R2 standard. The RC is working without any issues. The upgrade scenario is supported. At the very end of the process the upgrade fails giving me the following. _____ The SQL Server installation failed because a restart was pending on this computer. Restart the computer and then start DPM Setup again. ID: 4386. Details: Unknown error (0x84be0bc2) _____ Restarting the server does not correct the issue. On the next attempt I am getting the same error message. Where to look for the pending rest...

error 0x800cc0f
i installed windows xp, and i set up all my email accounts. they are all working , except one: i receive 0x800cc0f message, which states that the service has been interrupted, contact your ISP...., but this is not the case, since my internet conneciton is working fine all the account settings are correct I am having the same problem. I have to close outlook and reopen to retrieve all of my messages. Have you found a resolution yet? "Kerstin" wrote: > i installed windows xp, and i set up all my email > accounts. they are all working , except one: i receive > 0x800c...

Calculating age in a label or text box on a form
Hello All, I have a text box for birthdate for a user to enter the birthdate and I want to the age for the user to be automatically calcuated and displayed in another label called "Age." What formula can I use? Missy ...

opening .bak file
Hi, I hope someone can help! I recently was performing a compacting operation on my outlook express folders. My computer shutdown due to a power failure and I lost some emails from a few of my folders. I was however able to get the .bak files (of the .dbx files that were lost) out of the recycle bin. If I could open one of these .bak files or convert it back to the .dbx file from which it was created I would retrieve these emails. Can anyone instruct me as to open this .bak file? Thanks for any help! Arnie K. How did you get the bak files out of the Recycle Bin? All e...