Papa_Don 31 Posting Pro in Training

Group,

When publishing my first program, I noticed that it put the program in the App folder as opposed to "C:\Program Files\". Is there a way to direct where everything should be stored when you install it on the users computer?

Thanks,

Don

Papa_Don 31 Posting Pro in Training

Shark 1, I got it to work. I did find that the code readtxt.GetUpperBound(0) - 2 had to be changed to -4. Once I did that it worked exactly as I needed it. Thank you!

Papa_Don 31 Posting Pro in Training

Shark 1, no luck using your code. It doesn't appear to be doing anything. I was hoping it would drop the last two lines. But it doesn't seem to be doing it.

This prompts me to ask again, should you use StreamReader to loop through this? Since I know there are 232 lines, could I tell it to loop through StreamReader 230 times? If so, I can't seem to find the correct syntax to tell it to exit the "Using" early. Thoughts or ideas?

Papa_Don 31 Posting Pro in Training

I'm curious: Using the "System.IO.File.ReadAllLines("FileName")" syntax, is there a way to read a specific number of lines?

I've determined there are 232 lines in the first file. If I read only 230 of them, I've eliminated the last blank line and the line that contains "End of Report". Is this possible?

Papa_Don 31 Posting Pro in Training

I did do this to remove the "End of Report":

txtLine = Replace(txtLine, "End of Report", "")

Of course it still leaves the line. I'll play with this to see if I can't remove the whole line.

Papa_Don 31 Posting Pro in Training

There is a part two to my issue:

There is a blank line between the end of the last line of info and the line that contains "End of Report". I also need to delete this 1 line. My challenge is that there is a blank line between each row of data that I cannot delete.

So the question is: Is there some code that would delete not only the line containing "End of Report" but also the line before?

As always, Thanks.

Don

Papa_Don 31 Posting Pro in Training

Rubberman, I think your idea is probably a wise one. I'm disappointed I didn't think of it first. I guess I'm in too big a hurry to get this thing working right.

Minimalist, I'll try that one as well.

Papa_Don 31 Posting Pro in Training

Group,

I'm now having to merge several of these text files together. At the end of each of the text files is a line that says "End of Report". I need to eliminate this line completely.

This code does the merge for me:

                RestranName = getRestranName(0)
                RestranName2 = getRestranName(1)
                System.IO.File.AppendAllText(RestranName2, System.IO.File.ReadAllText(RestranName))

These files are UNIX created and are unformated. So I'm using the following code to format it correctly:

            ' This reads the text file for conversion
            txtLine = My.Computer.FileSystem.ReadAllText(RestranName)
            ' This begins to add the carriage returns in the appropriate places
            txtLine = Replace(txtLine, vbLf, vbCrLf)
            txtLine = Replace(txtLine, vbCr & vbCr, vbCr)
            txtLine = Replace(txtLine, """", "")
            ' This writes the line to the file
            My.Computer.FileSystem.WriteAllText(fileSave, txtLine, False)

This works perfectly. Unfortunately though I have "End of Report" between the two merged and formatted reports. I've got to figure out how to remove those words and the line (or spaces around it).

I've tried using StreamWriter to read the unformated but merged file (RestranName) to find the "End of Report" line using this code:

            Using reader As New StreamReader(RestranName)
                While Not reader.EndOfStream
                    Dim line As String = reader.ReadLine()
                    If line.Contains("End of Report") Then
                        badLine = line
                    Else
                        goodLine = line
                        My.Computer.FileSystem.WriteAllText(RestranName2, goodLine, True)
                    End If
                End While
            End Using

This works to remove the line that includes "End of Report". Unfortunately when it goes through the routine for formatting, it doesn't do it correctly. Any thoughts as to why? …

Papa_Don 31 Posting Pro in Training

tinstaafl, thanks for the code and the tips. Most importantly, it worked perfectly!

Thanks for the help!

Don

Papa_Don 31 Posting Pro in Training

Group,

I'm counting the number of files in a folder using the following code:

Dim counter = My.Computer.FileSystem.GetFiles(folderName)

This produces a value that doesn't appear to be either a string or an integer. Would you know how to convert this value into an integer that can be used?

Don

Papa_Don 31 Posting Pro in Training

OK... I won't change anything with this one. But I will certainly remember this the next time I build one.

Thank you everyone. This has been a enjoyable learning experience.

Don

Papa_Don 31 Posting Pro in Training

This prompts the question then: If I change it now, will I disrupt anything? Would it be best just to leave things alone and do nothing with this first program?

Thanks again.

Don

Papa_Don 31 Posting Pro in Training

I'm making some "cleanup" changes to my 1st VB.net project that I'm publishing. The project has an "Assembly Name". But I've just realized that the Root Namespace has the default name of "WindowsApplication1". I've got to believe this needs to be changed. How important is the name I put here? Is there any specific "naming convention" that I should use? Is this going to change anything to my project (where it will now be found, it's "file name", etc.)?

As always, thanks for the help.

Don

Papa_Don 31 Posting Pro in Training

Got it! Thanks group!

Don

imti321 commented: Welcome!! +2
Papa_Don 31 Posting Pro in Training

Group,

I've published my first VB.net program (woo hoo!). This prompts me to ask a couple of questions:

1) I'm using a couple of text files to hold some user updated info. Is there a way to have the setup program to create the folder and attached the text files in it (FYI.... I need the files save to the users "C" drive in a folder called "Restran Conversion")?

2) I've added a self created icon to the forms property. When the program is opened, this icon isn't display as it should in the task manager. It displays as a default "floppy disk". Have I done something incorrectly? Should I have included the icons within the program file somewhere?

As always, Thanks for your help!

Don

Papa_Don 31 Posting Pro in Training

Group,

I finally figured it out. Here's the final code:

        RestranName = "C:\Restran Conversion\IPSDATA\PM00213A\20141210.142601"
        Dim fileSave As String = "C:\Restran Conversion\IPSDATA\PM00213A\213RT20141210.txt"

        ' This reads the text file for conversion
        txtLine = My.Computer.FileSystem.ReadAllText(RestranName)
        ' This begins to add the carriage returns in the appropriate places
        txtLine = Replace(txtLine, vbLf, vbCrLf)
        txtLine = Replace(txtLine, vbCr & vbCr, vbCr)
        txtLine = Replace(txtLine, """", "")

        ' This writes the line to the file
        My.Computer.FileSystem.WriteAllText(fileSave, txtLine, False)

Again, thank you everyone for your help.

Don

Papa_Don 31 Posting Pro in Training

Rev. Jim / Minimalist, I'm attempting to convert the code to VB.net. I've got it to write something but it's writing only one line. I'm sure I need to use "Using" or some kind of loop for it to read and write each line. Here's what I've got so far:

            My.Computer.FileSystem.ReadAllText(RestranName)
            ' This begins to add the carriage returns in the appropriate places
            txtLine = Replace(Text, vbLf, vbCrLf)
            txtLine = Replace(Text, vbCr & vbCr, vbCr)
            txtLine = Replace(Text, """", "")

            ' This writes the line to the file
            My.Computer.FileSystem.WriteAllText(fileSave, txtLine, False)

I got an error message when I tried "Using". The line looked like this:

Using My.Computer.FileSystem.ReadAllText(RestranName)

The message said "Using operand of type "String" must implement "System.IDisposal". I'm not sure what it's trying to tell me.

Thought and ideas?

Thanks again.

Don

Papa_Don 31 Posting Pro in Training

Rev. Jim, I started to do something like that, but I didn't have much luck with "StreamReader". I'll give your code a whirl.

Thanks again!

Papa_Don 31 Posting Pro in Training

Rev. Jim, you're correct and that is my error.

Since this program is written in VBscript, I've looked for a way to run this "Convert.vbs" through a VB.net. I've tried

Dim fileStart As String = "C:\Restran Conversion\IPSDATA\PM00213A\Convert.vbs"
' 1st try
Process.Start("C:\Windows\System32\cscript.exe", fileStart)
' 2nd try
System.Diagnostics.Process.Start("C:\Windows\System32\wscript.exe", fileStart)

neither one of these will work as I get a an error message with the first one and nothing happens with the second. I've tried using wscript.exe in place of cscript.exe.

Again, Convert.vbs works perfectly when I double click it. Isn't there some way to emulate that via VB.net?

Don

Papa_Don 31 Posting Pro in Training

Minimalist, the code works perfectly! All is good! Excellent! Thank you, thank you, thank you!

Happy Holidays!

Don

Papa_Don 31 Posting Pro in Training

Minimalist, I've inserted "msgbox stringfolder" as line 6 in the script.

Yes, I really have 150 separate folders where this program will be inserted. I know that sounds odd. However I'm in the Hotel industry. We have 150 different properties in our group. As part of each hotels night audit, they generate this text file that is stored in the hotels specific folder. It's all on one server, but in their individual folder. This part of the reason I would have preferred to have written the code in VB.net as I had started a program that do the conversion after pushing a button on the users desktop.

I've attempted to run the script. The message box comes up and it says, "O:\IPSDATA\PMS00213" which is the correct path to the file in that folder. The file to be converted is specifically called "20141210.142601". However it doesn't appear to have done anything.

Any thoughts?

Papa_Don 31 Posting Pro in Training

Minimalist, Yes, the icon in the folder looks identical. I did save it in the actual folder where it is to work as "convert.vbs". "ANSI" was selected.

I've removed "Sub Main" and "End Sub" that I wrote in. I added the message box code to line 18. I've attempted to run it again with no results. Even the message box did not pop up. I even tried to "Open with command propmt" with no success.

Thank you again!

Papa_Don 31 Posting Pro in Training

Minimalist, be sure to see the questions above.

I've copied your script into Notepad and saved it as "convert.vbs". I double clicked it to run. Nothing happened. I tried inserting "Sub Main" and "End Sub" at the top and bottom. Again, nothing happened. Do I have something wrong? I've not added any paths to where a file to convert may be. I'm assuming that this is meant to convert any text file within the folder.

I look forward to hearing from you. I've got to believe this is a step in the right direction!

Don

Papa_Don 31 Posting Pro in Training

Minimalist, I've not run a VBscript in this manner before (in fact, only recently did I learn there was such a thing as VBscript). Does this mean that a copy of this program will need to be in every folder where the text file exists? In other words, I have 150 different files to convert. Each file will be in a separate folder. Will I need to place a copy of this program in each folder?

I certainly don't mind doing this. I only want to clarify.

I can't thank all of you enough for your help on this. I have researched and tried to do this on my own. I simply don't know enough to do this. But I'm learning with each step!

Don

Papa_Don 31 Posting Pro in Training

Bingo! tinsaafl, you're the man!

Thank you, thank you, thank you!

Don

Papa_Don 31 Posting Pro in Training

tinsaafl/Minimalist, I've made the changes you've suggested and have run the following:

Dim RestranName As String() = System.IO.Directory.GetFiles("C:\Restran Conversion\IPSDATA\PM00213A\20141210.", "*")

It's not finding the file. If I type in the actual path (C:\Restran Conversion\IPSDATA\PM00213A\20141210.142601), it finds it with no issues. This wildcard is so important. Any thoughts on what needs to be done?

Papa_Don 31 Posting Pro in Training

Rev. Jim, I don't see anything in your code that will direct it to where the original file will be found or where the new, "Save As" file will go. I've got to believe there are some lines of code that need to be inserted to tell it what to do.

For what it's worth, I've got about 150 of these kinds of files to convert. Thus the reason I wanted to write a script to do it. To this point, we've been screen scraping the data, then pasting that into a Notepad file. I finally convinced someone that the UNIX system should be able to generate the report for us. Now it's doing that, but I've got to "format" it to make it legible and useable.

I'm sure I could add to this to create a list of the individual files to run and let it loop through it over and over until it's completed.

As always, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Minimalist/tinstaafl, I've discovered this code causes an error message on a line further down in my code. It says:

Using SR As New System.IO.StreamReader(RestranName)

The variable "SR" has the error. The message says,

"Error 1 Overload resolution failed because no accessible 'New' can be called with these arguments:
'Public Sub New(path As String)': Value of type '1-dimensional array of String' cannot be converted to 'String'.
'Public Sub New(stream As System.IO.Stream)': Value of type '1-dimensional array of String' cannot be converted to 'System.IO.Stream'.

Is there a fix for this?

Papa_Don 31 Posting Pro in Training

Minimalist, what is the comma for (Dim dirs As String() = Directory.GetFiles("C:\Restran Conversion\IPSDATA\PM00213A\", "*.*"))? I would have assumed you would use and ampersand there. I see another teaching moment!

Thanks again.

Papa_Don 31 Posting Pro in Training

Rev. Jim, you indeed have the right idea. I'm going to use it. It's perfect. I knew there was a better way to write this. Thanks for the advice!

Don

Papa_Don 31 Posting Pro in Training

Rev. Jim,

Thanks for the above. To answer you first question, the file is indeed a text file (this is a presumption as the file is created by a UNIX based program. It does open in Notepad but it appears to have no carriage returns. To clarify, the .pdf file I attached was actually a picture of the actual file opened in Notepad.

I'm attempting to enter the code you supplied. However I'm getting some error messages. The first is "fso". Should this be defined as a "Object" or a "File" (I suppose it could be something else. If so, what)? It wouldn't allow me to write "set" as the first word in that line.

Also, what is "arg"? Is it a string? How should it be defined? Further, what about "Wscript"? It seems to want to be defined as well. Again, is this a string?

I appologize for having to ask these questions. All of this is new. This wasn't taught in the classes on Visual Basic I've taken.

As always, thank you for help and knowledge base.

Don

Papa_Don 31 Posting Pro in Training

I failed to mention that the file, "20141216.042615", was produced via a UNIX based program (I believe, but not completely sure).

Papa_Don 31 Posting Pro in Training

Group, there are actually a total of 20 ID's. Consequently I have 20 textboxes. Since I last updated, I've also created 20 labels. I've done this as I want to display the 20 ID's (as labels) and also to allow them to edit the list (via textboxes).

Here's what I've written:

        Dim objReader As New System.IO.StreamReader(FILE_NAME)
        Dim txtProps As String
        Dim i As Integer = 1
        If System.IO.File.Exists(FILE_NAME) = True Then

            Do While objReader.Peek() <> -1
                txtProps = objReader.ReadLine()
                If i = 1 Then
                    tbxProp1.Text = txtProps
                    lblProp1.Text = txtProps
                End If
                If i = 2 Then
                    tbxProp2.Text = txtProps
                    lblProp2.Text = txtProps
                End If
                If i = 3 Then
                    tbxProp3.Text = txtProps
                    lblProp3.Text = txtProps
                End If
                i = i + 1
            Loop
        Else
            MsgBox("File Does Not Exist")
        End If
        objReader.Close()

My code works fine, but I'm assuming there might be a better, more efficient way to do it (I really want to learn to be a good code writer!).

As always, thanks for your input. You guys are the best!

Don

Papa_Don 31 Posting Pro in Training

Group,

In a post in VB 4/5/6, I question how to open a file with a wildcard as the file extension (https://www.daniweb.com/software-development/visual-basic-4-5-6/threads/488809/accessing-a-file-with-a-ever-changing-name. That worked fine for VBA. However I'm trying to do the same thing using VB.net. I'm having trouble finding the correct syntax. I hope you can help.

Specifically, I have to find a file that has a varying file extension. The file name will be the creation date. The file extension is the time the file was created. So the file name looks like this: "20141216.042615". So I need to write my code so that it will go and find "20141216.(asterisk)" or whatever the appropriate wildcard character is. I've tried

Dim RestranName = "C:\Restran Conversion\IPSDATA\PM00213A\20141210.%"

However the error in the Immediate box says "A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll". So is there an appropriate way to connect with the file?

In advance, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

ddanbe,

Your suggestions make sense. I should have thought of inserting the data directly into the textboxes.

I'm not sure using If and Else is needed. It's going to be 1, 2 or 3 no matter what, albeit I'm actually having to insert data into 20 textsboxes (there are 20 different ID's in the actual text file).

As always, thanks for the help.

Don

Papa_Don 31 Posting Pro in Training

Group,

I'm taking a text file that is storing ID numbers in a single column that looks like this:

123
3050
3971

I'm looping through the text file line for line and putting each ID number into a textbox. My question is: Am I writing this code the most efficient way? Here's my code:

Dim FILE_NAME As String = "C:\Restran Conversion\RestranFileConversion.txt"
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Dim txtProps As String
Dim i As Integer = 1
If System.IO.File.Exists(FILE_NAME) = True Then

     Do While objReader.Peek() <> -1
        txtProps = objReader.ReadLine()
            If i = 1 Then
               prop1 = txtProps
            End If
            If i = 2 Then
               prop2 = txtProps
            End If
            If i = 3 Then
               prop3 = txtProps
            End If
        i = i + 1
        Loop

tbxProp1.Text = prop1
tbxProp2.Text = prop2
tbxProp3.Text = prop3

I'm thinking there is a programtically more efficient way to write this. If you have some thoughts, please do share!

As always, thanks for your responses.

Don

Papa_Don 31 Posting Pro in Training

Rev. Jim,

As always, thanks again for the help. However I want to make sure you understand that I don't want to use EXCEL at all.

I'm thinking that there has to be a way to read the file as you see it in Notepad_Picture.pdf. I'm assuming that this file is exported by the UNIX program as 1 line of text with all the spaces but without carriage returns, etc. Assuming that's correct (you may know something I don't as I've not seen this kind of output before), I'm thinking it may be best to parse this very long line and chop it up into a fixed number of characters and turn that into a line, then move to the next set of characters and make that a second line, and so forth and so on.

So my code would be something to the effect of

1) import the file and read it
2) parse the first 130 characters and move them to a new text file as line 1
3) Repeat this process until the "End of File"

Hopefully I'm making sense.

You're code above may do exactly what I'm thinking. But being a novice, I'm not sure how or what it's doing. This may be a good teaching moment.

FYI: The reason I want to abandon EXCEL to help with the conversion is that I've got multiple files to convert (right now, upwards of 130). So I thought I'd write a program in Visual Basic to …

Papa_Don 31 Posting Pro in Training

I meant to attach the file called 213Restran in the last note. I'm doing it here. I think now you'll see the quotes on various lines.

Papa_Don 31 Posting Pro in Training

Minimalist, my apologies. The second file had been altered and I forgot about that. I looked at the 19KB file and it appears to be formatted correctly.... Which surprises me. When I view it through Notepad, it not formatted. I'm not sure why it looks correct here. I'm going to try to attach a picture of what it looks like in Notepad. You can then look at the 19KB file again and see it as though it was delimited correctly.

Papa_Don 31 Posting Pro in Training

Minimalist, Keep in mind that this won't be a comma delimited file. I've attached two text files to show you how it comes across and what it needs to look like. Note: the "look like" file has quotes at the beginning and ending of the first group line. These cannot be there.

Again, thanks for your assistance!

Don

Papa_Don 31 Posting Pro in Training

Hello Group!

I am in need of converting a "text" file created by a UNIX based program (it is only semi-formatted) and put it into a more-formatted text (.txt) file. Put a different way, this needs to be converted such that it can be opened in Notepad and it be formatted correctly (and with no quote marks).

I've used some VBA language to open the file in EXCEL, apply the 1 delimiter at the end of the row and then save it as a EXCEL type of text file (xlText). Unfortunately it is adding beginning and ending quotes to every line. I cannot have these in there as I have other code that is then parsing the individual lines for use in another spreadsheet.

I'm pondering doing this conversion outside of EXCEL using Visual Basic as I have will have many of these to do each day and I think it will be much easier and faster.

Any thoughts or ideas?

Thanks for your assistance.

Don

Papa_Don 31 Posting Pro in Training

Minimalist, I've done some testing. The wildcards work perfectly! Thank you!!

Papa_Don 31 Posting Pro in Training

I may not be as clear as I should be: The code I'm writing is in VBA. I'm actually writting this behind some EXCEL documents. So the actual code you're suggesting I try would look like this?:

fileName = Year(Today()) & Month(Today()) & Day(Today())
filePath = "O:\IPSDATA\PMS03361A\" & fileName & ".*"

Is this correct?

Again, thanks for reaching out.

Papa_Don 31 Posting Pro in Training

Hello everyone!

Is there a way in VBA to find a file name that has an unknown portion to it? Let me explain:

Our computer system is UNIX based. It is creating a text file for us that uses the date, the hour, minutes and seconds that the file was created as its file name. This file name looks exactly like this:

20141210.104056

Finding the date isn't an issue. The unknown part is the date and time the file was created as the "file extension" (.104056) is the time stamp. That is the variable that I need to access.

Is there an "any extension" code such as "filePath = 20141210.(asterisk)" (or some other character) that would allow me to open this file?

In advance, thanks for your assistance.

Don

Papa_Don 31 Posting Pro in Training

Group,

I'm trying to improve a macro in an EXCEL spreadsheet. The spreadsheet has multiple tabs (sheets), some of which have grouped rows in them. My "cleanup" routine needs to check to see if these grouped rows exist. Is there some code that does this (hopefully boolean)?

If it helps, I'm using the following code to group:

    Rows(begRow & ":" & endRow).Select
    Selection.Rows.Group

However I only want to ungroup these sheets if grouping exists on the page anywhere.

Thoughts?

Thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

Danny,

Wow!! I love the thought process. Clearly you can see that, based on my limited programming skills, I've not completely understood the things that can be done via the "()" when you create your Sub. You just taught me some things. However I'm going to have questions for you when as work through this and try it out. I want to completely understand how it works.

This is awesome! Thanks!!

Don

Papa_Don 31 Posting Pro in Training

ddanbe, yes, the workbook is open when the code is run. For what it's worth, I've since re-run the reports from our server, opened them, saved them to my hard drive and ran the script and it worked fine. This leaves me to believe the file had changed in some manner or was corrupt in some way. Is there a specific definition of what the "Run-time error 9" really means?

I'm very aware of the indexing the sheets as 1, 2, 3, etc. However I have no choice but to do it this way as the individual sheet names vary as to the information that is in them. Thankfully though, a sheet really doesn't have the opportunity to be deleted.

Thanks for the ideas. I'm still learning about programming. So I'm still at the stage where these issues are less of a problem and more of a learning experience/opportunity.

Don

Papa_Don 31 Posting Pro in Training

ddanbe,

There are only 4 sheets in the workbook. For what it's worth, I'm rerunning the data (which creates these spreadsheets that are to be "activated"). I'm now going on the assumption that they my have been formatted incorrectly or have some kind of corruption to them. I say this as I've rerun the first one (which produced the original error) and it went through the macro fine. However the second one crashed. Thus the reason for recreating the data and spreadsheets.

If it is of interest, here's the code I've written:

Sub ImportReport1()

    Windows("All Same Store Rate Plan Production.xlsx").Activate
    sheetNo1 = ActiveWorkbook.Worksheets.Count

    'Sheet1
If sheetNo1 > 0 Then
    Windows("All Same Store Rate Plan Production.xlsx").Activate
    Sheets(1).Select
    name1 = Range("A12").Value
    name2 = Range("A13").Value
    If name1 = "Business Category" Then
        name2 = ""
    Windows("All Same Store Rate Plan Production.xlsx").Activate
    Sheets(1).Select
    Range("A1:K5").Select
    Selection.Copy
    Windows("YTD Rate Plan Production Master.xlsm").Activate
    Sheets("Data1").Select
    Range("B1").Select
    ActiveSheet.Paste
    Range("A15").Select
    Windows("All Same Store Rate Plan Production.xlsx").Activate
    Sheets(1).Select
    Range("A6:K11").Select
    Selection.Copy
    Windows("YTD Rate Plan Production Master.xlsm").Activate
    Sheets("Data1").Select
    Range("B7").Select
    ActiveSheet.Paste
    Range("A15").Select
    Windows("All Same Store Rate Plan Production.xlsx").Activate
    Sheets(1).Select
    Range("A12:K7000").Select
    Selection.Copy
    Windows("YTD Rate Plan Production Master.xlsm").Activate
    Sheets("Data1").Select
    Range("B13").Select
    ActiveSheet.Paste
    Range("A15").Select
    End If

    If name2 = "Business Category" Then
        name1 = ""
    Windows("All Same Store Rate Plan Production.xlsx").Activate
    Sheets(1).Select
    Range("A1:K11").Select
    Selection.Copy
    Windows("YTD Rate Plan Production Master.xlsm").Activate
    Sheets("Data1").Select
    Range("B1").Select
    ActiveSheet.Paste
    Range("A15").Select
    Windows("All Same Store Rate Plan Production.xlsx").Activate
    Sheets(1).Select
    Range("A13:K7000").Select
    Selection.Copy
    Windows("YTD Rate Plan Production Master.xlsm").Activate
    Sheets("Data1").Select
    Range("B13").Select
    ActiveSheet.Paste
    Range("A15").Select
    End If
End If

    'Sheet2/Four Points
If sheetNo1 > 1 Then
    Windows("All Same Store Rate Plan Production.xlsx").Activate …
Papa_Don 31 Posting Pro in Training

Group,

I've created a large spreadsheet with a fair amount of code behide it. Historically it has run well and with no issues. However it has started giving me a "Run-time error '9': Subscript out of range" error. I have no idea what is causing it. It is stoping at the beginning of a new sub. The code says:

Windows("All Same Store Rate Plan Production.xlsx").Activate 'failure is here
sheetNo1 = ActiveWorkbook.Worksheets.Count

I can promise, the spreadsheet it is referring to is open. It is named correctly. Can anyone offer some ideas as to why this error is coming up?

In advance, thanks for your help.

Don

Papa_Don 31 Posting Pro in Training

tinstaafl,

I've begun looking through the guide and it's some help. I've attempted the following code, but it's pausing for several seconds and telling me it's "Not Responding". Then it finishes with the last "i", posts that value and the finishes (I'm testing this in EXCEL). Now I'm wondering why it's stopping and then starting. Any thoughts?

Sub TimeCheck()

    Dim i As Integer
    Dim startTime As String
    Dim curTime As String
    Dim am As String
    Dim hh As String
    Dim mm As String
    Dim ss As String

    startTime = Hour(Now()) & ":" & Minute(Now()) & ":" & Second(Now())

    For i = 1 To 10000
        If Hour(Now()) < 12 Then
            am = "AM"
            hh = "0" & Hour(Now())
            mm = Minute(Now())
            If mm < 10 Then
                mm = "0" & mm
            End If
            ss = Second(Now())
        Else
            am = "PM"
            hh = Hour(Now()) - 12
            mm = Minute(Now())
            If mm < 10 Then
                mm = "0" & mm
            End If
            ss = Second(Now())
        End If

        curTime = hh & ":" & mm & ":" & ss & am

        Range("A1").Value = startTime
        Range("A2").Value = curTime
        Range("A4").Value = i

    Next i

End Sub