VBA Macro not working in network drive.

kcanbarasu

New Member
Joined
Mar 3, 2020
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hi There,

i have created one VBA macro to pull all the information from other sheet and copied into the new sheet where VBA macro used. This macro works fine if i execute it in my local drive (C:\). If i copy this macro into network drive, it is not working fine.

The VBA Code is as below.

Sub CombineFiles()

Dim Path As String
Dim FileName As String
Dim Wkb As Workbook
Dim ws As Worksheet

Application.EnableEvents = False
Application.ScreenUpdating = False
macrowkb = ThisWorkbook.Name
Path = ThisWorkbook.Worksheets("Macro").Range("D5").Value
If Path <> "" Then
FileName = Dir(Path & "\*.xls", vbNormal)
Do Until FileName = ""
Set Wkb = Workbooks.Open(FileName:=Path & "\" & FileName)
ActiveSheet.AutoFilterMode = False
Range("F3:F14").Copy
ThisWorkbook.Activate
Sheets("TrackerSheet").Select
ActiveSheet.AutoFilterMode = False
lr = Range("a1048576").End(xlUp).Row
Cells(lr + 1, 1).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Application.CutCopyMode = False
Wkb.Activate
Wkb.Close False
FileName = Dir()
Loop
End If
ThisWorkbook.Activate
Sheets("TrackerSheet").Select
Range("N:N").Clear
Range("N2").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(C[-11],RC[-11])"
ActiveCell.Copy
lr = Range("a1048576").End(xlUp).Row
Range("N3:N" & lr).PasteSpecial xlPasteFormulas
Application.CutCopyMode = False
For Each aCell In Range("N2:N" & lr)
If aCell.Value > 1 Then
Range("L" & aCell.Row).Value = "Duplicate. Please check"
End If
Next
Range("M:M").Clear

Cells.Select
Application.CutCopyMode = False
With Selection.Font
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.TintAndShade = 0
End With


Application.EnableEvents = True
Application.ScreenUpdating = True
MsgBox "Done"
End Sub
Sub Excel_Input_File_1()

Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = Application.DefaultFilePath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
ThisWorkbook.Worksheets("Macro").Range("D5").Value = sItem
Set fldr = Nothing
End Sub
Sub test()
'For Each ws In Wkb.Worksheets
'ActiveSheet.AutoFilterMode = False
'Range("F4:F10").Select
'Range("L1").Value = "Check"
'Range("L2").Select
'ActiveCell.FormulaR1C1 = "=COUNTIF([" & macrowkb & "]TrackSheet!C6,RC[-6])"
'Selection.Copy
'lr = Range("a1048576").End(xlUp).Row
'Range("L3:L" & lr).PasteSpecial xlPasteFormulas
'Selection.Copyx
'Application.CutCopyMode = False
'Range("a1").Select
'Range("a1:l" & lr).AutoFilter Field:=12, Criteria1:="0"
'If Range("a1048576").End(xlUp).Row <> 1 Then
'lr = Range("a1048576").End(xlUp).Row
'Range("a2:j" & lr).SpecialCells(xlCellTypeVisible).Copy
'End If
'Range("F4:F10").Copy
'ws.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
'Next ws
End Sub

Please help to fix this issue?

Thanks,
Anbu
 

Some videos you may like

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

ranman256

Well-known Member
Joined
Jun 17, 2014
Messages
1,930
dont use drive letters for network paths, f:\folder\folder\file.xls
some folks dont have that letter mapped.

instead always use UNC paths with the full server name....
\\myserver\folder\folder\file.xls
 

Watch MrExcel Video

Forum statistics

Threads
1,118,358
Messages
5,571,708
Members
412,413
Latest member
dvprajapati
Top