open excel workbook vba

need help with the correct syntax based on the code sample.  I need to close then reopen a workbook after it has been saved.  what is the proper syntax?

            Set myBook = Nothing
            On Error Resume Next
            Set myBook = Workbooks.Open(MyPath & MyFiles(FNum), UpdateLinks:=0)

                    If ShName = "ResPlan_Data" Then
                        Call UnpivotResPlan
                        myBook.Save
                        myBook.Close
                        mybook.????

                     End If
                        

Open in new window

Karen SchaeferBI ANALYSTAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
Why are you closing and reopening the workbook? There may be alternatives to eliminate this requirement.
Karen SchaeferBI ANALYSTAuthor Commented:
because I need update the data in one workbook, then save it then access the saved data.  When I tried to use active worksheet.  the data was not copied into the master template, but if I reran the code the saved file was able to update the master template.  So this was my workaround, and I got it work acceptably.

                 If ShName = "ResPlan_Data" Then
                        Call UnpivotResPlan
                        myBook.Close savechanges:=True
                        Set myBook = Workbooks.Open(MyPath & MyFiles(FNum), UpdateLinks:=0)
                        Set ws = myBook.Worksheets(ShName)
                     End If
                        
                        '**************************************************
                        'Updates template data per shName
                        '*************************************************
                        If Not ws Is Nothing Then
                            Set BaseWks = wbMaster.Worksheets(ShName)
                            Set sourceRange = ws.UsedRange
                            'Exclude header labels
                            Set rng = sourceRange.Offset(1, 0).Resize(sourceRange.Rows.Count - 1, sourceRange.Columns.Count)
    
                            RwCount = rng.Rows.Count
                            rnum = BaseWks.Cells(BaseWks.Rows.Count, 1).End(xlUp).Row + 1
    
                            BaseWks.Cells(rnum, "A").Resize(RwCount).Value _
                                  = myBook.Name
                            BaseWks.Cells(rnum, "B").Resize(RwCount, rng.Columns.Count).Value = rng.Value
                        End If
                        With wbMaster.Worksheets(ShName).ListObjects(1)
                            On Error Resume Next
                                .DataBodyRange.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
                            On Error GoTo 0
                        End With
                
            Next ShName

Open in new window

Roy CoxGroup Finance ManagerCommented:
If the code is in the workbook that you are closing then it cannot re-open itself. So what is MyBook referring to here

 myBook.Close savechanges:=True

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Karen SchaeferBI ANALYSTAuthor Commented:
thanks again
Roy CoxGroup Finance ManagerCommented:
Pleased to help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.