Home

Cell value in header

%3CLINGO-SUB%20id%3D%22lingo-sub-1148638%22%20slang%3D%22en-US%22%3ECell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1148638%22%20slang%3D%22en-US%22%3E%3CP%3EPS%3A%20If%20there%20is%20another%20way%20to%20do%20this%2C%20like%20reference%20a%20named%20section%20somehow%20from%20within%20the%20header%2C%20that's%20what%20the%20%5E%5BDoc%5D%20was%20meant%20to%20be.%20But%20everything%20online%20points%20to%20VBA.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20would%20the%20page%20header%20to%20display%20some%20values%20from%20the%20workbook%20as%20values%20in%20the%20header.%26nbsp%3B%20I%20did%20google%20this%20and%20none%20of%20the%20results%20we're%20able%20to%20produce%20anything%20working.%20Not%20even%20any%20errors%2C%20the%20headers%20just%20stay%20blank.%3CBR%20%2F%3ESo%20here%20is%20what%20I%20would%20like%20to%20be%20referenced%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F168699iFCCD5335B38F89DF%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_1.png%22%20title%3D%22clipboard_image_1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20here%20is%20the%20VBA%20code%20I%20have%20been%20trying%20to%20make%20work.%20This%20is%20just%20the%20latest%20snippet%20I%20have%20worked%20with%2C%20Its%20been%20a%20few%20days%20of%20scouring%20the%20internet%20for%20something%20that%20will%20work.%20I%20am%20convinced%20it's%20my%20implementation%20that%20is%20incorrect.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EFunction%20Author()%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EAuthor%20%3D%20ThisWorkbook.BuiltinDocumentProperties(%22Author%22)%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EEnd%20Function%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EFunction%20Doc()%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EDoc%20%3D%20Worksheets(%22WorkInstructions%22).Range(%22D2%22).Value%20%3D%20ThisWorkbook.CustomDocumentProperties.Item(%22Doc%22).Value%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EEnd%20Function%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EPrivate%20Sub%20Workbook_BeforePrint(Cancel%20As%20Boolean)%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EDim%20sTemp%20As%20String%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EWith%20Worksheets(%22WorkInstructions%22)%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EsTemp%20%3D%20.Range(%22Z4%22).Text%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EPageSetup.LeftHeader%20%3D%20sTemp%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EEnd%20With%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3E%3CFONT%20face%3D%22arial%2Chelvetica%2Csans-serif%22%3EAny%20input%20on%20this%20matter%20would%20be%20greatly%20appreciated%2C%20even%20if%20you%20don't%20think%20you%20have%20the%20answer.%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FFONT%3E%3CBR%20%2F%3E%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1148638%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1148761%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1148761%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F543554%22%20target%3D%22_blank%22%3E%40MrSassyBritches%3C%2FA%3EPlease%20elaborate%20as%20to%20the%20determining%20factor%20for%20what%20data%20appears..%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1148763%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1148763%22%20slang%3D%22en-US%22%3EThe%20text.%20Whatever%20text%20is%20in%20the%20cell%20Z2%20I%20want%20to%20be%20displayed%20in%20the%20top%20left%20of%20the%20header.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1148771%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1148771%22%20slang%3D%22en-US%22%3Ewithin%20the%20sheet%20or%20when%20printed%20%2C%2C%20or%20both%20%3F%3F%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1148779%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1148779%22%20slang%3D%22en-US%22%3E%3CP%3EWell%20the%20header%20wont%20be%20visible%20until%20printed%2C%20so%20when%20printed%20I%20guess.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1148781%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1148781%22%20slang%3D%22en-US%22%3EI%20probably%20don't%20fully%20understand.%3CBR%20%2F%3E%3CBR%20%2F%3EBut%20can%20you%20not%20insert%20a%20formula%20at%20A1%20that%20references%20Z2..%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1148797%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1148797%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F543554%22%20target%3D%22_blank%22%3E%40MrSassyBritches%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20bout%20making%20a1%20(%20or%20what%20ever%20cell%20you%20choose%20)%2C%20%3Dz2%20and%20then%20designate%20row%201%20as%20a%20row%20title%20for%20printing.%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1148805%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1148805%22%20slang%3D%22en-US%22%3Ewould%20it%20be%20better%20to%20discuss%20via%20phone..%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1148823%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1148823%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F543554%22%20target%3D%22_blank%22%3E%40MrSassyBritches%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethink%20it%20would%20be%20best%20if%20we%20discussed%20via%20phone%20%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1148837%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1148837%22%20slang%3D%22en-US%22%3E%3CP%3EI%20can%20assure%20you%20my%20communication%20skills%20only%20get%20worse%20verbally.%20I%20am%20not%20looking%20for%20a%20row%20title%2C%20as%20that%20is%20already%20present%20in%20my%20workbook.%3C%2FP%3E%3CP%3EHere%20is%20a%20screenshot%20to%20visualize.%3CBR%20%2F%3E%3CBR%20%2F%3EHere%20it%20is%20now%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F168725iE04B73919361D496%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eand%20here%20is%20what%20I%20am%20looking%20for%20(notice%20the%20100%20in%20the%20top%20left)%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F168726iF380A78EC48D5537%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_1.png%22%20title%3D%22clipboard_image_1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20dont%20want%20the%20user%20to%20have%20to%20edit%20the%20header%2C%20they%20edit%20that%20cell%20next%20to%20%22Doc%22%20and%20have%20the%20header%20use%20that%20cell.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1148874%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1148874%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F543554%22%20target%3D%22_blank%22%3E%40MrSassyBritches%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethinkin%20I%20understand%20now.....%26nbsp%3B%20researching%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1149466%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1149466%22%20slang%3D%22en-US%22%3EThe%20VBA%20solution%20didn%E2%80%99t%20work%3F%3CBR%20%2F%3E%3CBR%20%2F%3EPrivate%20Sub%20Workbook_BeforePrint(Cancel%20As%20Boolean)%3CBR%20%2F%3EActiveSheet.PageSetup.CenterHeader%20%3D%20Range(%22Z4%22).Value%3CBR%20%2F%3EEnd%20Sub%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1150369%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1150369%22%20slang%3D%22en-US%22%3ESo%20the%20code%20I%20found%20online%2C%20in%20my%20original%20post%20at%20the%20top%2C%20I%20could%20not%20get%20to%20work.%20The%20functions%20Author()%20and%20Doc()%20do%20work.%20I%20just%20tried%20what%20you%20posted%20and%20could%20not%20get%20it%20to%20work%2C%20do%20I%20need%20something%20like%20%5E%5BWorkbook_BeforePrint%5D%20in%20the%20header%20or%20something%20along%20those%20lines%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1150396%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1150396%22%20slang%3D%22en-US%22%3EYou%20need%20to%20create%20the%20code%20for%20the%20workbook%2C%20not%20in%20a%20sheet.%3CBR%20%2F%3EOpen%20VBA%20editor%2C%20double%20click%20%E2%80%98This%20Workbook%E2%80%99%20in%20the%20Microsoft%20Excel%20Objects%20folder%20(in%20the%20%E2%80%98Project%20-%20VBAProject%E2%80%99%20panel%20to%20the%20left).%20In%20the%20code%20window%2C%20you%20will%20see%20two%20drop%20down%20menus%3B%20in%20the%20first%20select%20Workbook%20and%20the%20second%20Before%20Print...then%20type%20the%20rest%20of%20the%20code%20as%20below.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1150749%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1150749%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F543554%22%20target%3D%22_blank%22%3E%40MrSassyBritches%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EOk%2C%20so%20I%20just%20tested%20this%20myself%20and%20also%20couldn't%20get%20it%20to%20work.%20I%20found%20a%20solution%20(or%20rather%20a%20workaround)%20from%20the%20Microsoft%20support%20pages....So%2C%20if%20you%20do%20as%20per%20my%20last%20post%20BUT%20also%20enter%20the%20same%20code%20in%20a%20regular%20module%2C%20it%20will%20work.%20Although%20the%20background%20code%20is%20'BeforePrint'%20the%20header%20does%20not%20actually%20display%20until%20it%20has%20been%20printed.%3CBR%20%2F%3E%3CBR%20%2F%3ELet%20me%20know%20if%20you%20can%20get%20it%20working.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1151042%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1151042%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F531239%22%20target%3D%22_blank%22%3E%40Charla74%3C%2FA%3E%26nbsp%3BThanks%20so%20much%20for%20the%20reply.%20I%20think%20I%20followed%20your%20instructions.%20Here%20is%20a%20screenshot%20of%20%22ThisWorkbook%22%20and%20the%20exact%20same%20code%20is%20inside%20%22Module1%22.%20Does%20this%20look%20correct%20per%20your%20instructions%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F169010i38BA219CB1B1AAD4%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1151063%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1151063%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F543554%22%20target%3D%22_blank%22%3E%40MrSassyBritches%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3ELooks%20good%20-%20Give%20her%20a%20print%20and%20let%20me%20know%20if%20it%20works.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1151251%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1151251%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F531239%22%20target%3D%22_blank%22%3E%40Charla74%3C%2FA%3E%26nbsp%3BI%20printed%20and%20got%20an%20error%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F169029i2DAC3BC944DE36D1%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_2.png%22%20title%3D%22clipboard_image_2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EAs%20for%20the%20result%2C%20there%20was%20nothing%20printed%20on%20the%20center%20header%20%3CLI-EMOJI%20id%3D%22lia_confused-face%22%20title%3D%22%3Aconfused_face%3A%22%3E%3C%2FLI-EMOJI%3E%3CBR%20%2F%3EFirst%20I%20printed%20to%20a%20PDF%2C%20I%20then%20printed%20to%20a%20physical%20printer%20and%20both%20had%20the%20same%20result%2C%20no%20center%20header.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1151291%22%20slang%3D%22en-US%22%3ERe%3A%20Cell%20value%20in%20header%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1151291%22%20slang%3D%22en-US%22%3EI%20wasn%E2%80%99t%20sure%20but%20I%20suspected%20that%20the%20two%20FUNCTION%20segments%2C%20in%20the%20Worksheet%20code%2C%20may%20cause%20an%20issue.%20If%20you%20remove%20those%20two%20parts%20of%20the%20code%20and%20leave%20them%20as%20they%20are%20in%20the%20regular%20module%20you%20may%20have%20a%20better%20outcome.%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

PS: If there is another way to do this, like reference a named section somehow from within the header, that's what the ^[Doc] was meant to be. But everything online points to VBA.

I would the page header to display some values from the workbook as values in the header.  I did google this and none of the results we're able to produce anything working. Not even any errors, the headers just stay blank.
So here is what I would like to be referenced:

clipboard_image_1.png

 

And here is the VBA code I have been trying to make work. This is just the latest snippet I have worked with, Its been a few days of scouring the internet for something that will work. I am convinced it's my implementation that is incorrect. 

 

Function Author()
Author = ThisWorkbook.BuiltinDocumentProperties("Author")
End Function

 

Function Doc()
Doc = Worksheets("WorkInstructions").Range("D2").Value = ThisWorkbook.CustomDocumentProperties.Item("Doc").Value
End Function

 

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim sTemp As String

With Worksheets("WorkInstructions")
sTemp = .Range("Z4").Text
PageSetup.LeftHeader = sTemp
End With
End Sub

Any input on this matter would be greatly appreciated, even if you don't think you have the answer.

18 Replies
Highlighted

@MrSassyBritchesPlease elaborate as to the determining factor for what data appears..?

Highlighted
The text. Whatever text is in the cell Z2 I want to be displayed in the top left of the header.
Highlighted
within the sheet or when printed ,, or both ??

Well the header wont be visible until printed, so when printed I guess.

Highlighted
I probably don't fully understand.

But can you not insert a formula at A1 that references Z2..?
Highlighted

@MrSassyBritches 

How bout making a1 ( or what ever cell you choose ), =z2 and then designate row 1 as a row title for printing.?

 

Highlighted
would it be better to discuss via phone..?
Highlighted

@MrSassyBritches 

 

think it would be best if we discussed via phone ?

Highlighted

I can assure you my communication skills only get worse verbally. I am not looking for a row title, as that is already present in my workbook.

Here is a screenshot to visualize.

Here it is now

clipboard_image_0.png

 

and here is what I am looking for (notice the 100 in the top left)

clipboard_image_1.png

 

I dont want the user to have to edit the header, they edit that cell next to "Doc" and have the header use that cell.

Highlighted

@MrSassyBritches 

thinkin I understand now.....  researching

Highlighted
The VBA solution didn’t work?

Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.CenterHeader = Range("Z4").Value
End Sub
Highlighted
So the code I found online, in my original post at the top, I could not get to work. The functions Author() and Doc() do work. I just tried what you posted and could not get it to work, do I need something like ^[Workbook_BeforePrint] in the header or something along those lines?
Highlighted
You need to create the code for the workbook, not in a sheet.
Open VBA editor, double click ‘This Workbook’ in the Microsoft Excel Objects folder (in the ‘Project - VBAProject’ panel to the left). In the code window, you will see two drop down menus; in the first select Workbook and the second Before Print...then type the rest of the code as below.
Highlighted
@MrSassyBritches

Ok, so I just tested this myself and also couldn't get it to work. I found a solution (or rather a workaround) from the Microsoft support pages....So, if you do as per my last post BUT also enter the same code in a regular module, it will work. Although the background code is 'BeforePrint' the header does not actually display until it has been printed.

Let me know if you can get it working.
Highlighted

@Charla74 Thanks so much for the reply. I think I followed your instructions. Here is a screenshot of "ThisWorkbook" and the exact same code is inside "Module1". Does this look correct per your instructions?

clipboard_image_0.png

Highlighted
@MrSassyBritches

Looks good - Give her a print and let me know if it works.
Highlighted

@Charla74 I printed and got an error:

clipboard_image_2.png

As for the result, there was nothing printed on the center header
First I printed to a PDF, I then printed to a physical printer and both had the same result, no center header.

 

Highlighted
I wasn’t sure but I suspected that the two FUNCTION segments, in the Worksheet code, may cause an issue. If you remove those two parts of the code and leave them as they are in the regular module you may have a better outcome.