macro codes(help please)

shaskool33

New Member
Joined
Jul 21, 2011
Messages
7
this is my codes
I don`t know where is the problem
it says sub or function not defined
please help




Sub FindFeeder()

Dim i, m, n, z, Setting_var_dc As Integer
Dim path As String
Dim DIName, OCName, DIfeeder, OCfeeder, OCfeederN, OCNameN As String
Dim station, Datei As Object
Dim ControlOC, ControlDI, flag_reg As Boolean
Dim Line_Name(0 To 300) As String

' Initialisation
ControlOC = False
ControlDI = False
FeederFound = False
path_dc = "G:\Azarbayjan"


If Different_Node = False Then
path = path_dc & "\" & RegionName

' Create FileSystemObject
Set fs = CreateObject("Scripting.FileSystemObject")

' Find active protection devices in the chosen region
Set f1 = fs.GetFolder(path + "\Protection")
Set f2 = f1.subfolders
End If

If Different_Node = True Then
GoTo jump
End If

For Each station In f2

jump:
' Open each prot-file in folder
If Different_Node Then
Set g2 = station2.Files
Else
Set g2 = station.Files
End If

For Each Datei In g2
If Different_Node Then
stationname = station2.Name
Else
stationname = station.Name
End If

flagDI = False
flagOC_both = False
flagOC = False
flagOCN = False
DIfeeder = ""
OCfeeder = ""
OCfeederN = ""
For z = 1 To 1
' If prot-file and voltage level >= 230kV then open it
If UCase(Left(Datei.Name, 4)) = "PROT" And Mid(Datei.Name, 6, 1) > 7 Then

wbook = Datei.Name
pathwbook = Datei.ParentFolder.path

Setting_var_dc = 0


If UCase(Left(Datei.Name, 4)) = "PROT" And Mid(Datei.Name, 6, 1) > 7 Then
Setting_var_dc = 0
wbook = Datei.Name
pathwbook = Datei.ParentFolder.path
End If
If getValue(pathwbook, wbook, "21_21N", 11, 4) <> "" And getValue(pathwbook, wbook, "21_21N", 11, 6) = "" Then
pathwbook.wbook("21_21N", 11, 6) = pathwbook.wbook("21_21N", 11, 4)
End If
End If
Next
Next
Next
End Sub
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Welcome to the Forum,

from the sample you need to go into the VBA Screen Select the Tools Menu, the References then scroll down the list to Microsoft Scripting XX and tick the box.

How have you declared the GetValue, as I can't see it.
 
Last edited:
Upvote 0
Welcome to the Forum,

from the sample you need to go into the VBA Screen Select the Tools Menu, the References then scroll down the list to Microsoft Scripting XX and tick the box.

How have you declared the GetValue, as I can't see it.
thanks for the reply
I did this but it didnt solve the problem.
should i define the " getvalue" at the begining?
 
Last edited:
Upvote 0
Yes you need to define the getValue as something, and I would place at the beginning, where you have the other Dim statements.

What should getValue do?
 
Upvote 0
forget about getvalue
I have about 1000 excel files that all have a sheet named " 21_21N".
I need the macro to open all that files and make some changes in the "21_21N" sheet.
pathwbook is the path of the folder containing the excel files.
each excel file name will save into wbook.
what should i use instead of getvalue?
 
Last edited:
Upvote 0
This coded will look to open all workbooks in a folder and make a change, you can adpat it to select the sheet and alter what ever you need.


Sub Open_My_Files()
Dim MyFile As String
MyPath = "M:\Access Files\"
MyFile = Dir(MyPath)
Do While MyFile <> ""
If MyFile Like "*.xls" Then
Workbooks.Open MyPath & MyFile
Sheets(1).Select 'Change to "21_21N"
Range("C3") = 6 'Change to what you need it to do
ActiveWorkbook.Close True
End If
MyFile = Dir
Loop
End Sub
 
Upvote 0
the codes open the files but cannot select "21_21N" sheet
it says " subscript out of range"
here is the codes:

If UCase(Left(Datei.Name, 4)) = "PROT" And Mid(Datei.Name, 6, 1) > 7 Then

wbook = Datei.Name
pathwbook = Datei.ParentFolder.path
Setting_var_dc = 0


MyFile = wbook
Do While MyFile <> ""
Open wbook For Random As FreeFile
Sheets("21_21N").Select
If Cells(11, 4) <> "" And Cells(11, 6) = "" Then 'Change to what you need it to do
Cells(11, 6) = Tabelle6.Cells(11, 4)
ActiveWorkbook.Close True

MyFile = Dir
End If
 
Upvote 0
Have you stepped through the code? to see where the fault is......and is the sheet name correct?

Have you set bookmarks to stop at various steps?

In your code you have, near the end

MyFile = Dir
End If

you should have

ActiveWorkbook.Close True
End If
MyFile = Dir
Loop
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top