View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Doogie Doogie is offline
external usenet poster
 
Posts: 7
Default Excel macro - personal folder

On Jul 30, 2:07*pm, Doogie wrote:
On Jul 30, 1:58*pm, Dave Peterson wrote:





When I have this kind of thing, I'll write the code to use the activesheet.


Any chance your code is specific in what sheet it uses?


You may want to post your code if this doesn't help.


Doogie wrote:


I have created an excel macro and stored it in my personal.xlsm
workbook. *I can access it from other workbooks just fine, but when I
execute it, it always executes the functionality against
personal.xlsm. *How do I get it to ignore personal.xlsm and execute
against the other workbook I have open?


--


Dave Peterson


Here's my code. *I don't have any place that I can see a thisWorkbook
from the other person's post so couldn't make those changes. (there
are more than 2 cases in my case statement, but I only put two here
for demonstrative purposes).

Sub changeTabNames()
* * Dim worksheetValue As String
* * Dim tabName As String
* * Dim worksheet

* * For Each worksheet In Worksheets
* * * * worksheetValue = Left(worksheet.Range("A6"), 2)

* * * * Select Case worksheetValue
* * * * * * Case "4D"
* * * * * * * * tabName = "4D-BALID"
* * * * * * Case "4I"
* * * * * * * * tabName = "4I-HNCUT"
* * * * End Select

* * * * worksheet.Name = tabName
* * Next

End Sub- Hide quoted text -

- Show quoted text -


I figured it out. I had to go one step up and check the
workbook...the only thing, I'm hardcoding a look for the
"personal.xlsm" file, which if there was a better way to do that I'd
like to.

Sub changeTabNames()
Dim worksheetValue As String
Dim tabName As String
Dim worksheet
Dim workbook

For Each workbook In Workbooks
If (workbook.Name < "personal.xlsm") Then
For Each worksheet In workbook.Worksheets
worksheetValue = Left(worksheet.Range("A6"), 2)

Select Case worksheetValue
Case "4D"
tabName = "4D-BALID"
Case "4I"
tabName = "4I-HNCUT"
End Select
Next
End If
Next

End Sub