MassSpecGuru
Board Regular
- Joined
- Feb 23, 2010
- Messages
- 55
Hello everybody!
I was wondering if I could get some help with some VBA code. I'm using Excel 2003 and am a complete novice to VBA, thus the request. For a work project, I'm trying to take some data from a laboratory instrument (as a .txt file), parse it, massage it, and sort it using Excel and generate an .xls file to upload the data to another company's website.
I can get the data sorted and parsed properly using general Excel worksheet functions; however, I want to automate as much of the process as possible using macros or VBA code. To this end, I've gone through some of the steps manually using macro recorder, modified it as much as I can, but I have a couple problems and/or questions (which I'll post separately).
My first problem is that when I open the text files of data, the recorded macro has the name of the template (spreadsheet) hardcoded into it. For example,
.
.
.
Selection.Copy
Windows( "Method #1 Template.xls").Activate
Sheets("Instrument Data").Select
.
.
.
One of the issues I foresee is that we run several diferent methods so eventually I'll have a named method template for each analysis (i.e. they will have completely different names, and not Method #1, Method #2, etc., but something like "Nitrate", "Sulfate", "Chloride", etc.) and I don't want to have go in and change the code for all 25 (so far) buttons I have inside so that the macros will run properly.
Is there a way to get the template filename automatically and have it (Excel) enter it where needed inside each macro? If it matters, the path can't be hardcoded either because the templates may be on different computers, hard drives, and in different locatons (i.e. folders) on the drive depending on instrument and user.
Thanks for your assistance!
I was wondering if I could get some help with some VBA code. I'm using Excel 2003 and am a complete novice to VBA, thus the request. For a work project, I'm trying to take some data from a laboratory instrument (as a .txt file), parse it, massage it, and sort it using Excel and generate an .xls file to upload the data to another company's website.
I can get the data sorted and parsed properly using general Excel worksheet functions; however, I want to automate as much of the process as possible using macros or VBA code. To this end, I've gone through some of the steps manually using macro recorder, modified it as much as I can, but I have a couple problems and/or questions (which I'll post separately).
My first problem is that when I open the text files of data, the recorded macro has the name of the template (spreadsheet) hardcoded into it. For example,
.
.
.
Selection.Copy
Windows( "Method #1 Template.xls").Activate
Sheets("Instrument Data").Select
.
.
.
One of the issues I foresee is that we run several diferent methods so eventually I'll have a named method template for each analysis (i.e. they will have completely different names, and not Method #1, Method #2, etc., but something like "Nitrate", "Sulfate", "Chloride", etc.) and I don't want to have go in and change the code for all 25 (so far) buttons I have inside so that the macros will run properly.
Is there a way to get the template filename automatically and have it (Excel) enter it where needed inside each macro? If it matters, the path can't be hardcoded either because the templates may be on different computers, hard drives, and in different locatons (i.e. folders) on the drive depending on instrument and user.
Thanks for your assistance!